1- Most quoted items by decades

1.1- 1980-1989

setwd("C:/Users/jgrad/Desktop/Network_Quality/Network_Quality")


load("Data_7_finalbase.rda")


#####################################################################################################################
#####################################################################################################################
# Modification qualitative d'erreurs restantes constatées en explorant la base: Can be continued -------------------
#####################################################################################################################
#####################################################################################################################


eoeoe$identifiant[eoeoe$identifiant=="LANCASTER (1966) 74  65) 132"]<-"LANCASTER (1966) 74 132"
eoeoe$identifiant[eoeoe$identifiant=="LANCASTER (1966) AB 74"]<-"LANCASTER (1966) 74 132"
eoeoe$identifiant[eoeoe$identifiant=="LANCASTER (1971) AB 40"]<-"LANCASTER (1971) AB AB"
eoeoe$identifiant[eoeoe$identifiant=="LANCASTER (1972) AB AB"]<-"LANCASTER (1971) AB AB"
eoeoe$identifiant[eoeoe$identifiant=="LANCASTER , 1971. AB AB"]<-"LANCASTER (1971) AB AB"
eoeoe$identifiant[eoeoe$identifiant=="LANCASTER (1980) 116 281"]<-"LANCASTER (1979) AB AB"        
eoeoe$identifiant[eoeoe$identifiant=="AKERLOF (1970) AB 89"]<-"AKERLOF (1970) 84 488"
eoeoe$identifiant[eoeoe$identifiant=="AKERLOF (1970) AB AB"]<-"AKERLOF (1970) 84 488"
eoeoe$identifiant[eoeoe$identifiant=="MUSSA (1978) AB AB"]<-"MUSSA (1978) 18 301"
eoeoe$identifiant[eoeoe$identifiant=="BAGWELL (1985) AB AB"]<-"BAGWELL (1988) 19 59"
eoeoe$identifiant[eoeoe$identifiant=="BAGWELL (2007) AB AB"]<-"BAGWELL (2007) 3 1701"
eoeoe$identifiant[eoeoe$identifiant=="BAGWELL (1988) AB AB"]<-"BAGWELL (1991) 81 224"
eoeoe$identifiant[eoeoe$identifiant=="BAGWELL (1991) 81 . AB"]<-"BAGWELL (1991) 81 224"
eoeoe$identifiant[eoeoe$identifiant=="BAGWELL 1991 81 AB"]<-"BAGWELL (1991) 81 224"
eoeoe$identifiant[eoeoe$identifiant=="TIROLE (1990) AB AB"]<-"TIROLE (1988) AB AB"
eoeoe$identifiant[eoeoe$identifiant=="TIROLE (1994) AB AB"]<-"TIROLE (1988) AB AB"
eoeoe$identifiant[eoeoe$identifiant=="TIROLE (1998) AB AB"]<-"TIROLE (1988) AB AB"
eoeoe$identifiant[eoeoe$identifiant=="SPENCE (1973) AB AB"]<-"SPENCE (1973) 87 355"


# On calcule la fréquence de chaque identifiant

freq<-table(eoeoe$identifiant)
freq<-as.data.frame(freq)

# On stocke la fréquence comme nouvelle variable, ce qui nous servira à renseigner la taille des noeuds dans les graphes

eoeoe$frequence<-0
for(i in 1:nrow(eoeoe)){
  j<-which(eoeoe$identifiant[i] == freq$Var1)
  eoeoe$frequence[i]<-freq$Freq[j]
}



load("./Data_5_nodes.rda")


desco$Datepubli<-as.character(desco$Datepubli)
eoeoe$anneecitant<-0
for(i in 1:nrow(eoeoe)){
  j<-which(eoeoe$V2[i] == desco$Cartel)
  eoeoe$anneecitant[i] <- desco$Datepubli[j]
}


library(readr)
library(stringr)

eoeoe$anneecitant<-str_replace_all(string = eoeoe$anneecitant, pattern = "\\(", replacement = "")
eoeoe$anneecitant<-str_replace_all(string = eoeoe$anneecitant, pattern = "\\)", replacement = "")
eoeoe$anneecitant<-as.numeric(eoeoe$anneecitant)


freq19811990<-eoeoe[eoeoe$anneecitant==1980|eoeoe$anneecitant==1981|eoeoe$anneecitant==1982|eoeoe$anneecitant==1983|eoeoe$anneecitant==1984|eoeoe$anneecitant==1985|eoeoe$anneecitant==1986|eoeoe$anneecitant==1987|eoeoe$anneecitant==1988|eoeoe$anneecitant==1989,]
freq19912000<-eoeoe[eoeoe$anneecitant==1990|eoeoe$anneecitant==1991|eoeoe$anneecitant==1992|eoeoe$anneecitant==1993|eoeoe$anneecitant==1994|eoeoe$anneecitant==1995|eoeoe$anneecitant==1996|eoeoe$anneecitant==1997|eoeoe$anneecitant==1998|eoeoe$anneecitant==1999,]
freq20012010<-eoeoe[eoeoe$anneecitant==2000|eoeoe$anneecitant==2001|eoeoe$anneecitant==2002|eoeoe$anneecitant==2003|eoeoe$anneecitant==2004|eoeoe$anneecitant==2005|eoeoe$anneecitant==2006|eoeoe$anneecitant==2007|eoeoe$anneecitant==2008|eoeoe$anneecitant==2009,]
freq20112020<-eoeoe[eoeoe$anneecitant==2010|eoeoe$anneecitant==2011|eoeoe$anneecitant==2012|eoeoe$anneecitant==2013|eoeoe$anneecitant==2014|eoeoe$anneecitant==2015|eoeoe$anneecitant==2016|eoeoe$anneecitant==2017|eoeoe$anneecitant==2018|eoeoe$anneecitant==2019,]

freq19811990<-table(freq19811990$identifiant)
freq19811990<-as.data.frame(freq19811990)

freq19912000<-table(freq19912000$identifiant)
freq19912000<-as.data.frame(freq19912000)

freq20012010<-table(freq20012010$identifiant)
freq20012010<-as.data.frame(freq20012010)

freq20112020<-table(freq20112020$identifiant)
freq20112020<-as.data.frame(freq20112020)




top19811990<-freq19811990[rev(order(freq19811990$Freq)),]
top19912000<-freq19912000[rev(order(freq19912000$Freq)),]
top20012010<-freq20012010[rev(order(freq20012010$Freq)),]
top20112020<-freq20112020[rev(order(freq20112020$Freq)),]


top19811990<-top19811990[1:nrow(top19811990),]
top19912000<-top19912000[1:nrow(top19912000),]
top20012010<-top20012010[1:nrow(top20012010),]
top20112020<-top20112020[1:nrow(top20112020),]



row.names(top19811990)<-1:nrow(top19811990)
row.names(top19912000)<-1:nrow(top19912000)
row.names(top20012010)<-1:nrow(top20012010)
row.names(top20112020)<-1:nrow(top20112020)


top19811990<-top19811990[1:25,]
top19912000<-top19912000[1:25,]
top20012010<-top20012010[1:25,]
top20112020<-top20112020[1:25,]


for(i in 1:nrow(top19811990)){
  j<-which(top19811990$Var1[i] == eoeoe$identifiant)
  z<-which(paste(eoeoe$Firstauthor[j],eoeoe$Datepubli[j],eoeoe$Issue[j],eoeoe$Page[j])==eoeoe$identifiant[j])[1]
  top19811990$V1[i] <- eoeoe$V1[j[z]]
}


for(i in 1:nrow(top19912000)){
  j<-which(top19912000$Var1[i] == eoeoe$identifiant)
  z<-which(paste(eoeoe$Firstauthor[j],eoeoe$Datepubli[j],eoeoe$Issue[j],eoeoe$Page[j])==eoeoe$identifiant[j])[1]
  top19912000$V1[i] <- eoeoe$V1[j[z]]
}

for(i in 1:nrow(top20012010)){
  j<-which(top20012010$Var1[i] == eoeoe$identifiant)
  z<-which(paste(eoeoe$Firstauthor[j],eoeoe$Datepubli[j],eoeoe$Issue[j],eoeoe$Page[j])==eoeoe$identifiant[j])[1]
  top20012010$V1[i] <- eoeoe$V1[j[z]]
}

for(i in 1:nrow(top20112020)){
  j<-which(top20112020$Var1[i] == eoeoe$identifiant)
  z<-which(paste(eoeoe$Firstauthor[j],eoeoe$Datepubli[j],eoeoe$Issue[j],eoeoe$Page[j])==eoeoe$identifiant[j])[1]
  top20112020$V1[i] <- eoeoe$V1[j[z]]
}



top19811990<-top19811990[,c(3)]
top19912000<-top19912000[,c(3)]
top20012010<-top20012010[,c(3)]
top20112020<-top20112020[,c(3)]


top19811990<-as.data.frame(top19811990)
top19912000<-as.data.frame(top19912000)
top20012010<-as.data.frame(top20012010)
top20112020<-as.data.frame(top20112020)



names(top19811990)[names(top19811990) == "top19811990"] <- "Most quoted references 1980-1989"
names(top19912000)[names(top19912000) == "top19912000"] <- "Most quoted references 1990-1999"
names(top20012010)[names(top20012010) == "top20012010"] <- "Most quoted references 2000-2009"
names(top20112020)[names(top20112020) == "top20112020"] <- "Most quoted references 2010-2019"





for(i in 1:nrow(top19811990)){
  top19811990$`Most quoted references 1980-1989`[i]<-paste(i,"-",top19811990$`Most quoted references 1980-1989`[i])
}

for(i in 1:nrow(top19912000)){
  top19912000$`Most quoted references 1990-1999`[i]<-paste(i,"-",top19912000$`Most quoted references 1990-1999`[i])
}

for(i in 1:nrow(top20012010)){
  top20012010$`Most quoted references 2000-2009`[i]<-paste(i,"-",top20012010$`Most quoted references 2000-2009`[i])
}


for(i in 1:nrow(top20112020)){
  top20112020$`Most quoted references 2010-2019`[i]<-paste(i,"-",top20112020$`Most quoted references 2010-2019`[i])
}





library(knitr)
library(kableExtra)


kable(top19811990)
Most quoted references 1980-1989
1 - Selten, R., Re-examination of the perfectness concept for equilibrium points in extensive games (1975) International J. Game Theory, 4, pp. 25-55;
2 - Hotelling, H., Stability in competition (1929) The Economic Journal, 39 (153), pp. 41-57;
3 - Akerlof, G.A., The market for” lemons”: Quality uncertainty and the market mechanism (1970) The quarterly journal of economics, 84 (3), pp. 488-500;
4 - Salop, S.C., Monopolistic competition with outside goods (1979) Bell J. Econom., 10 (1), pp. 141-156;
5 - Lancaster, K., (1979) Variety, Equity, and Efficiency., , New York: Columbia University Press;
6 - Dixit, A., Stiglitz, J., Monopolistic competition and optimum product diversity (1977) American Economic Review, 67 (3), pp. 297-308;
7 - Spence, A.M., Product selection, fixed costs, and monopolistic competition (1976) Review of Economic Studies, 43 (2), pp. 217-235;
8 - Mussa, M., Rosen, S., Monopoly and product quality (1978) Journal of Economic theory, 18, pp. 301-317;
9 - D’Aspremont, C., Gabszewicz, J., Thisse, J.F., On Hotelling’s Stability in Competition (1979) Econometrica, 47, pp. 1145-1151;
10 - Shapiro, C., Premiums for high quality products as returns to reputations (1983) The Quarterly Journal of Economics, 98 (4), pp. 659-679;
11 - Shaked, A., Sutton, J., Relaxing Price Competition Through Product Differentiation (1982) Review of Economic Studies, 49, pp. 3-13;
12 - Prescott, E.C., Visscher, M., Sequential location among firms with foresight (1977) Bell Journal of Economics, 8, pp. 378-393;
13 - Harsanyi, J., Games with incomplete information played by Bayesian players (1967) Manage. Sci., 14, pp. 159-182;
14 - Varian, H., A Model of Sales (1980) A.E. R, 70, pp. 651-659;
15 - Scherer, F.M., (1980) Industrial Market Structure and Economic Performance, , Second ed. Chicago: Rand McNally;
16 - Rubinstein, A., Perfect equilibrium in a bargaining model (1982) Econometrica, 50, pp. 97-109;
17 - Rodriguez, C.A., The Quality of Imports and the Differential Welfare Effects of Tariffs, Quotas, and Quality Controls as Protective Devices (1979) Canadian Journal of Economics, 12, pp. 439-449;
18 - Milgrom, P., Roberts, J., Limit pricing and entry under incomplete information: an equilibrium analysis (1982) Econometrica, 50, pp. 443-459;
19 - Grossman, S., The informational role of warranties and private disclosure about product quality (1981) J. Law Econ., 24 (3), pp. 461-483;
20 - Falvey, R., “The Composition of Trade within Import-Restricted Products Categories” (1979) Journal of Political Economy, 87, pp. 1105-1114;
21 - Economides, The principle of minimum differentiation revisited (1982) Discussion paper no. 134, , Columbia University, New York;
22 - Chan, Y.S., Leland, H., Prices and Qualities in Markets with Costly Information," (1982) Review of Economic Studies, 49, pp. 499-516;
23 - Spence, A.M., Monopoly, quality, and regulation (1975) Bell Journal of Economics, 6 (2), pp. 417-429;
24 - Sobel, J., Takahashi, I., A multistage model of bargaining (1983) Review of Economic Studies, 50, pp. 411-426;
25 - Shilony, Y., Mixed pricing in oligopoly (1977) Journal of Economic Theory, 14, pp. 373-388;

1.2- 1990-1999

kable(top19912000)
Most quoted references 1990-1999
1 - Tirole, J., (1988) The theory of industrial organization, , MIT Press;
2 - Akerlof, G.A., The market for” lemons”: Quality uncertainty and the market mechanism (1970) The quarterly journal of economics, 84 (3), pp. 488-500;
3 - Mussa, M., Rosen, S., Monopoly and product quality (1978) Journal of Economic theory, 18, pp. 301-317;
4 - Milgrom, P., Roberts, J., Price and advertising signals of product quality (1986) The Journal of Political Economy, 94 (4), pp. 796-821;
5 - Klein, B., Leffler, K.B., The role of market forces in assuring contractual performance (1981) Journal of Political Economy, 89 (4), pp. 615-641;
6 - Shaked, A., Sutton, J., Relaxing Price Competition Through Product Differentiation (1982) Review of Economic Studies, 49, pp. 3-13;
7 - Cho, I.K., Kreps, D., Signaling games and stable equilibria (1987) Quart. J. Econom, 102 (2), pp. 179-221;
8 - Farrell, J., Saloner, G., Standardization, Compatibility and Innovation (1985) The Rand Journal of Economics, 16, pp. 70-83;
9 - Crosby, P.B., (1979) Quality Is Free, , McGraw-Hill New York;
10 - Katz, M.L., Shapiro, C., Technology adoption in the presence of network externalities (1986) Journal of Political Economy, 94, pp. 822-841;
11 - Hotelling, H., Stability in competition (1929) The Economic Journal, 39 (153), pp. 41-57;
12 - Nelson, P., Advertising as information (1974) The Journal of Political Economy, 82 (4), pp. 729-754;
13 - Porter, M.E., (1980) Competitive Strategy, , The Free Press, New York;
14 - Nelson, P., Information and consumer behavior (1970) The Journal of Political Economy, 78 (2), pp. 311-329;
15 - Kreps, D.M., Wilson, R., Sequential Equilibria (1982) Econometrica, 50, pp. 863-894;
16 - Katz, M., Shapiro, C., Network externalities, competition, and compatibility (1985) American Economic Review, 75 (3), pp. 424-440;
17 - Farrell, J., Saloner, G., Installed base and compatibility: Innovation, product preannouncements, and prédation (1986) American Economic Review, 76 (5), pp. 940-955;
18 - Shapiro, C., Premiums for high quality products as returns to reputations (1983) The Quarterly Journal of Economics, 98 (4), pp. 659-679;
19 - Parasuraman, A., Zeithaml, V.A., Berry, L.L., A conceptual model of service quality and its implications for future research (1985) Journal of Marketing, 49, pp. 41-50;
20 - Deming, W.E., (1986) Out of the Crisis, , MIT Press Cambridge, MA;
21 - David, P.A., Clio and the economics of QWERTY (1985) American Economic Review, 75, pp. 332-337;
22 - Bagwell, K., Riordan, M.H., High and declining prices signal product quality (1991) American Economic Review, 81 (1), pp. 224-239;
23 - Parasuraman, A., Berry, L.L., Zeithaml, V.A., Zeithaml, V.A., Berry, L.L., SERVQUAL: Multiple-item scale for measuring consumer perceptions of service quality (1988) Journal of Retailing, 64 (1), pp. 12-40;
24 - Saraph, J.V., Benson, P.G., Schroeder, R.G., An instrument for measuring the critical factors of quality management (1989) Decis. Sci., 20 (4), pp. 810-829;
25 - Oliver, R.L., A cognitive model of the antecedents and consequences of satisfaction decisions (1980) Journal of Marketing Research, 17, pp. 460-469., November;

1.3- 2000-2009

kable(top20012010)
Most quoted references 2000-2009
1 - Akerlof, G.A., The market for” lemons”: Quality uncertainty and the market mechanism (1970) The quarterly journal of economics, 84 (3), pp. 488-500;
2 - Tirole, J., (1988) The theory of industrial organization, , MIT Press;
3 - Mussa, M., Rosen, S., Monopoly and product quality (1978) Journal of Economic theory, 18, pp. 301-317;
4 - Powell, T.C., Total quality management as competitive advantage: A review and empirical study (1995) Strateg. Manag. J., 16 (1), pp. 15-37;
5 - Flynn, B.B., Schroeder, R.G., Sakakibara, S., A framework for quality management research and an associated measurement instrument (1994) J. Oper. Manag., 11 (4), pp. 339-366;
6 - Deming, W.E., (1986) Out of the Crisis, , MIT Press Cambridge, MA;
7 - Samson, D., Terziovski, M., The relations between total quality management practices and operational performance (1999) Journal of Operations Management, 17 (4), pp. 393-409;
8 - Terziovski, M., Samson, D., Dow, D., The business value of quality management systems certification. Evidence from Australia and New Zealand (1997) J. Oper. Manag., 15, pp. 1-18;
9 - Klein, B., Leffler, K.B., The role of market forces in assuring contractual performance (1981) Journal of Political Economy, 89 (4), pp. 615-641;
10 - Milgrom, P., Roberts, J., Price and advertising signals of product quality (1986) The Journal of Political Economy, 94 (4), pp. 796-821;
11 - Hair, J.F., Jr., Anderson, R.E., Tatham, R.L., Black, W.C., (1998) Multivariate data analysis, , Prentice-Hall, Englewood Cliffs, NJ;
12 - Ahire, S.L., Golhar, D.Y., Waller, M.A., Development and validation of TQM implementation constructs (1996) Decis. Sci., 27 (1), pp. 23-53;
13 - Shapiro, C., Premiums for high quality products as returns to reputations (1983) The Quarterly Journal of Economics, 98 (4), pp. 659-679;
14 - Saraph, J.V., Benson, P.G., Schroeder, R.G., An instrument for measuring the critical factors of quality management (1989) Decis. Sci., 20 (4), pp. 810-829;
15 - Nunnally, J.C., (1978) Psychometric Theory, , seconded. McGraw-Hill New York;
16 - Nelson, P., Information and consumer behavior (1970) The Journal of Political Economy, 78 (2), pp. 311-329;
17 - Anderson, S.W., Daly, D., Johnson, M.F., Why Firms Seek ISO 9000 Certification: Regulatory Compliance or Competitive Advantage (1999) Production and Operations Management, 8 (1), pp. 28-43;
18 - Parasuraman, A., Berry, L.L., Zeithaml, V.A., Zeithaml, V.A., Berry, L.L., SERVQUAL: Multiple-item scale for measuring consumer perceptions of service quality (1988) Journal of Retailing, 64 (1), pp. 12-40;
19 - Darby, M., Karni, E., Free competition and the optimal amount of fraud (1973) Journal of Law and Economics, 16, pp. 67-88;
20 - Berry, S., Levinsohn, J., Pakes, A., Automobile Prices in Market Equilibrium (1995) Econometrica, 63, pp. 841-890;
21 - Flynn, B.B., Schroeder, R.G., Sakakibara, S., The impact of quality management practices on performance and competitive advantage (1995) Decis. Sci., 26 (5), pp. 659-691;
22 - Dean, J.W., Bowen, D.E., Management theory and total quality: Improving research and practice through theory development (1994) Academy of Management Review, 19 (3), pp. 392-418;
23 - Nelson, P., Advertising as information (1974) The Journal of Political Economy, 82 (4), pp. 729-754;
24 - Anderson, J.C., Gerbing, D.W., Structural equation modeling in practice: A review and recommended two-step approach (1988) Psychol. Bull., 103 (3), pp. 411-423;
25 - Hackman, J.R., Wageman, R., Total quality management: Empirical, conceptual, and practical issues (1995) Administrative Science Quarterly, 40 (2), pp. 309-343;

1.4- 2010-2019

kable(top20112020)
Most quoted references 2010-2019
1 - Melitz, M., The impact of trade on intra-industry reallocations and aggregate industry productivity (2003) Econometrica, 71 (6), pp. 1695-1725;
2 - Verhoogen, E., Trade, quality upgrading and wage inequality in the Mexican manufacturing sector (2008) Q. J. Econ., 123 (2), pp. 489-530
3 - Khandelwal, A., The long and short (of) quality ladders (2010) Rev. Econ. Stud., 77 (4), pp. 1450-1476;
4 - Akerlof, G.A., The market for” lemons”: Quality uncertainty and the market mechanism (1970) The quarterly journal of economics, 84 (3), pp. 488-500;
5 - Nelson, P., Information and consumer behavior (1970) The Journal of Political Economy, 78 (2), pp. 311-329;
6 - Melitz, M., Ottaviano, G., Market size, trade, and productivity (2008) Rev. Econ. Stud., 75, pp. 295-316;
7 - Schott, P.K., “Across-Product versus Within-Product Specialization in International Trade,” (2004) Quarterly Journal of Economics, 119, pp. 647-678;
8 - Hallak, J.C., “Product Quality and the Direction of Trade,” (2006) Journal of International Economics, 68, pp. 238-265;
9 - Bernard, A.B., Bradford Jensen, J., Redding, S.J., Schott, P.K., Firms in International Trade (2007) J. Econ. Perspectives, 21, pp. 105-130., (Summer);
10 - Bernard, A.B., Eaton, J., Jensen, J.B., Kortum, S., Plants and productivity in international trade (2003) Am. Econ. Rev., 93 (4), pp. 1268-1290;
11 - Hummels, D., Klenow, P., The Variety and Quality of a Nations Exports.” (2005) A.E.R., 95, pp. 704-723., (June);
12 - Kugler, M., Verhoogen, E., Prices, plant size, and product quality (2012) Rev. Econ. Stud., 79 (1), pp. 307-339;
13 - Olley, G.S., Pakes, A., The Dynamics of Productivity in the Telecommunications Equipment Industry (1996) Econometrica, 64, pp. 1263-1297;
14 - Baldwin, R., Harrigan, J., Zeros, quality and space: trade theory and trade evidence (2011) Am. Econ. J.: Microecon., 3, pp. 60-88;
15 - Corbett, C.J., Montes-Sancho, M.J., Kirsch, D.A., The financial impact of ISO 9000 certification in the United States: an empirical analysis (2005) Manag Sci, 51, pp. 1046-1059;
16 - Helpman, E., Melitz, M., Rubinstein, Y., Estimating trade flows: trading partners and trading volumes (2008) The Quarterly Journal of Economics, 123 (2), pp. 441-487;
17 - Broda, C., Weinstein, D.E., ‘Globalization and the Gains from Variety’ (2006) Quarterly Journal of Economics, 121, pp. 541-586;
18 - King, A.A., Lenox, M.J., Terlaak, A., The strategic use of decentralized institutions: exploring certification with the ISO 14001 management standard (2005) Academy of Management Journal, 48, pp. 1091-1106;
19 - Hallak, J.C., Schott, P.K., “Estimating Cross-Country Differences in Product Quality,” (2011) Quarterly Journal of Economics, 126, pp. 417-474;
20 - Foster, L., Haltiwanger, J., Syverson, C., “Reallocation, Firm Turnover, and Efficiency: Selection on Productivity or Profitability?,” (2008) American Economic Review, 98, pp. 394-425;
21 - Chaney, T., Distorted Gravity: The Intensive and Extensive Margins of International Trade (2008) A.E.R., 98, pp. 1707-1721., (September);
22 - Tirole, J., (1988) The theory of industrial organization, , MIT Press;
23 - Mussa, M., Rosen, S., Monopoly and product quality (1978) Journal of Economic theory, 18, pp. 301-317;
24 - Eaton, J., Kortum, S., Technology, Geography, and Trade (2002) Econometrica, 70, pp. 1741-1779., (September);
25 - Maertens, M., Swinnen, J.F.M., Trade, standards, and poverty: evidence from Senegal (2009) World Dev., 37 (1), pp. 161-178;

1.5- Summary chart

top19811990<-freq19811990[rev(order(freq19811990$Freq)),]
top19912000<-freq19912000[rev(order(freq19912000$Freq)),]
top20012010<-freq20012010[rev(order(freq20012010$Freq)),]
top20112020<-freq20112020[rev(order(freq20112020$Freq)),]


top19811990<-top19811990[1:nrow(top19811990),]
top19912000<-top19912000[1:nrow(top19912000),]
top20012010<-top20012010[1:nrow(top20012010),]
top20112020<-top20112020[1:nrow(top20112020),]



top19811990$Freq<-1:nrow(top19811990)
top19912000$Freq<-1:nrow(top19912000)
top20012010$Freq<-1:nrow(top20012010)
top20112020$Freq<-1:nrow(top20112020)


top19811990$YEAR<-"1980-1989"
top19912000$YEAR<-"1990-1999"
top20012010$YEAR<-"2000-2009"
top20112020$YEAR<-"2010-2019"


top19811990<-top19811990[1:25,]
top19912000<-top19912000[1:25,]
top20012010<-top20012010[1:25,]
top20112020<-top20112020[1:25,]


top<-rbind(top19811990,top19912000,top20012010,top20112020)

library(ggplot2)
library(dplyr)


top$Var1<-str_replace_all(string = top$Var1, pattern = "D'ASPREMONT", replacement = "DASPREMONT")

top$Var1<-str_replace_all(string = top$Var1, pattern = " [[:digit:]].*$", replacement = "")

top$Var1<-str_replace_all(string = top$Var1, pattern = " AB.*$", replacement = "")




my_theme <- function() {
  
  # Colors
  color.background = "white"
  color.text = "#22211d"
  
  # Begin construction of chart
  theme_bw(base_size=15) +
    
    # Format background colors
    theme(panel.background = element_rect(fill=color.background,
                                          color=color.background)) +
    theme(plot.background  = element_rect(fill=color.background,
                                          color=color.background)) +
    theme(panel.border     = element_rect(color=color.background)) +
    theme(strip.background = element_rect(fill=color.background,
                                          color=color.background)) +
    
    # Format the grid
    theme(panel.grid.major.y = element_blank()) +
    theme(panel.grid.minor.y = element_blank()) +
    theme(axis.ticks       = element_blank()) +
    
    # Format the legend
    theme(legend.position = "none") +
    
    # Format title and axis labels
    theme(plot.title       = element_text(color=color.text, size=5, face = "bold")) +
    theme(axis.title.x     = element_text(size=0, color="black", face = "bold")) +
    theme(axis.title.y     = element_text(size=0, color="black", face = "bold",
                                          vjust=1.25)) +
    theme(axis.text.x      = element_text(size=0, vjust=0.5, hjust=0.5,
                                          color = color.text)) +
    ### Taille des nombre
    theme(axis.text.y      = element_text(size=2.5, color = color.text)) +
    theme(strip.text       = element_text(face = "bold")) +
    
    # Plot margins
    # Contour du graphique
    theme(plot.margin = unit(c(0, 0.2, 0.3, 0), "cm"))
}




library(ggiraph)



gg_point=ggplot(top,aes(x = as.factor(YEAR), y = Freq, group = Var1)) +
  # Taille des lignes
  geom_line_interactive(aes(color = Var1, alpha = 1,tooltip=Var1, data_id = Var1), size = 0.3) +
  # Taille des points
  geom_point_interactive(aes(x = as.factor(YEAR), y = Freq, group = Var1, color = Var1, alpha = 1, tooltip = Var1, data_id = Var1), size = 1) +
  geom_point_interactive(color = "#FFFFFF", size = 0.01) +
  scale_y_reverse(breaks = 1:table(top$YEAR)[[1]]) + 
  scale_x_discrete(breaks = 1:length(table(top$YEAR))) +
  theme(legend.position = 'none') +
  # le x designe le positionnement des auteurs à gauche
  geom_text(data = top %>% filter(YEAR == "1980-1989"),
            aes(label = Var1, x = 0.42) , hjust = 0.0,
            fontface = "bold", color = "#888888", size = 0.7) +
  # idem mais à droite
  geom_text(data = top %>% filter(YEAR == "2010-2019"),
            aes(label = Var1, x = 4.5) , hjust = 1.0,
            fontface = "bold", color = "#888888", size = 0.7) +
  labs(x = '', y = '', title = 'Most quoted references (1980-1989, 1990-1999, 2000-2009, 2010-2019)') +
  my_theme() 




girafe(ggobj = gg_point, width_svg = 3, height_svg = 2,
       options = list(
         opts_hover_inv(css = "opacity:0.1;"),
         opts_hover(css = "stroke-width:2;")
       ))

2- Most quoted authors by decades

2.1- Table

setwd("C:/Users/jgrad/Desktop/Network_Quality/Network_Quality")


load("Data_7_finalbase.rda")


#####################################################################################################################
#####################################################################################################################
# Modification qualitative d'erreurs restantes constatées en explorant la base: Can be continued -------------------
#####################################################################################################################
#####################################################################################################################


eoeoe$identifiant[eoeoe$identifiant=="LANCASTER (1966) 74  65) 132"]<-"LANCASTER (1966) 74 132"
eoeoe$identifiant[eoeoe$identifiant=="LANCASTER (1966) AB 74"]<-"LANCASTER (1966) 74 132"
eoeoe$identifiant[eoeoe$identifiant=="LANCASTER (1971) AB 40"]<-"LANCASTER (1971) AB AB"
eoeoe$identifiant[eoeoe$identifiant=="LANCASTER (1972) AB AB"]<-"LANCASTER (1971) AB AB"
eoeoe$identifiant[eoeoe$identifiant=="LANCASTER , 1971. AB AB"]<-"LANCASTER (1971) AB AB"
eoeoe$identifiant[eoeoe$identifiant=="LANCASTER (1980) 116 281"]<-"LANCASTER (1979) AB AB"        
eoeoe$identifiant[eoeoe$identifiant=="AKERLOF (1970) AB 89"]<-"AKERLOF (1970) 84 488"
eoeoe$identifiant[eoeoe$identifiant=="AKERLOF (1970) AB AB"]<-"AKERLOF (1970) 84 488"
eoeoe$identifiant[eoeoe$identifiant=="MUSSA (1978) AB AB"]<-"MUSSA (1978) 18 301"
eoeoe$identifiant[eoeoe$identifiant=="BAGWELL (1985) AB AB"]<-"BAGWELL (1988) 19 59"
eoeoe$identifiant[eoeoe$identifiant=="BAGWELL (2007) AB AB"]<-"BAGWELL (2007) 3 1701"
eoeoe$identifiant[eoeoe$identifiant=="BAGWELL (1988) AB AB"]<-"BAGWELL (1991) 81 224"
eoeoe$identifiant[eoeoe$identifiant=="BAGWELL (1991) 81 . AB"]<-"BAGWELL (1991) 81 224"
eoeoe$identifiant[eoeoe$identifiant=="BAGWELL 1991 81 AB"]<-"BAGWELL (1991) 81 224"
eoeoe$identifiant[eoeoe$identifiant=="TIROLE (1990) AB AB"]<-"TIROLE (1988) AB AB"
eoeoe$identifiant[eoeoe$identifiant=="TIROLE (1994) AB AB"]<-"TIROLE (1988) AB AB"
eoeoe$identifiant[eoeoe$identifiant=="TIROLE (1998) AB AB"]<-"TIROLE (1988) AB AB"
eoeoe$identifiant[eoeoe$identifiant=="SPENCE (1973) AB AB"]<-"SPENCE (1973) 87 355"


# On calcule la fréquence de chaque identifiant

freq<-table(eoeoe$identifiant)
freq<-as.data.frame(freq)

# On stocke la fréquence comme nouvelle variable, ce qui nous servira à renseigner la taille des noeuds dans les graphes

eoeoe$frequence<-0
for(i in 1:nrow(eoeoe)){
  j<-which(eoeoe$identifiant[i] == freq$Var1)
  eoeoe$frequence[i]<-freq$Freq[j]
}





#################################################################################################################
#################################################################################################################
###### On fait la liste des auteurs les plus cités par décénnie --------------------------------------
#################################################################################################################
#################################################################################################################


load("Data_5_nodes.rda")



desco$Datepubli<-as.character(desco$Datepubli)
eoeoe$anneecitant<-0
for(i in 1:nrow(eoeoe)){
  j<-which(eoeoe$V2[i] == desco$Cartel)
  eoeoe$anneecitant[i] <- desco$Datepubli[j]
}


library(readr)
library(stringr)

eoeoe$anneecitant<-str_replace_all(string = eoeoe$anneecitant, pattern = "\\(", replacement = "")
eoeoe$anneecitant<-str_replace_all(string = eoeoe$anneecitant, pattern = "\\)", replacement = "")
eoeoe$anneecitant<-as.numeric(eoeoe$anneecitant)


freq19811990<-eoeoe[eoeoe$anneecitant==1980|eoeoe$anneecitant==1981|eoeoe$anneecitant==1982|eoeoe$anneecitant==1983|eoeoe$anneecitant==1984|eoeoe$anneecitant==1985|eoeoe$anneecitant==1986|eoeoe$anneecitant==1987|eoeoe$anneecitant==1988|eoeoe$anneecitant==1989,]
freq19912000<-eoeoe[eoeoe$anneecitant==1990|eoeoe$anneecitant==1991|eoeoe$anneecitant==1992|eoeoe$anneecitant==1993|eoeoe$anneecitant==1994|eoeoe$anneecitant==1995|eoeoe$anneecitant==1996|eoeoe$anneecitant==1997|eoeoe$anneecitant==1998|eoeoe$anneecitant==1999,]
freq20012010<-eoeoe[eoeoe$anneecitant==2000|eoeoe$anneecitant==2001|eoeoe$anneecitant==2002|eoeoe$anneecitant==2003|eoeoe$anneecitant==2004|eoeoe$anneecitant==2005|eoeoe$anneecitant==2006|eoeoe$anneecitant==2007|eoeoe$anneecitant==2008|eoeoe$anneecitant==2009,]
freq20112020<-eoeoe[eoeoe$anneecitant==2010|eoeoe$anneecitant==2011|eoeoe$anneecitant==2012|eoeoe$anneecitant==2013|eoeoe$anneecitant==2014|eoeoe$anneecitant==2015|eoeoe$anneecitant==2016|eoeoe$anneecitant==2017|eoeoe$anneecitant==2018|eoeoe$anneecitant==2019,]

freq19811990<-table(freq19811990$identifiant)
freq19811990<-as.data.frame(freq19811990)

freq19912000<-table(freq19912000$identifiant)
freq19912000<-as.data.frame(freq19912000)

freq20012010<-table(freq20012010$identifiant)
freq20012010<-as.data.frame(freq20012010)

freq20112020<-table(freq20112020$identifiant)
freq20112020<-as.data.frame(freq20112020)




top19811990<-freq19811990[rev(order(freq19811990$Freq)),]
top19912000<-freq19912000[rev(order(freq19912000$Freq)),]
top20012010<-freq20012010[rev(order(freq20012010$Freq)),]
top20112020<-freq20112020[rev(order(freq20112020$Freq)),]


top19811990<-top19811990[1:2000,]
top19912000<-top19912000[1:5000,]
top20012010<-top20012010[1:5000,]
top20112020<-top20112020[1:5000,]


####### On remplace les identifiants par la ref complète


for(i in 1:nrow(top19811990)){
  j<-which(top19811990$Var1[i] == eoeoe$identifiant)
  z<-which(paste(eoeoe$Firstauthor[j],eoeoe$Datepubli[j],eoeoe$Issue[j],eoeoe$Page[j])==eoeoe$identifiant[j])[1]
  top19811990$V1[i] <- eoeoe$V1[j[z]]
}

for(i in 1:nrow(top19912000)){
  j<-which(top19912000$Var1[i] == eoeoe$identifiant)
  z<-which(paste(eoeoe$Firstauthor[j],eoeoe$Datepubli[j],eoeoe$Issue[j],eoeoe$Page[j])==eoeoe$identifiant[j])[1]
  top19912000$V1[i] <- eoeoe$V1[j[z]]
}

for(i in 1:nrow(top20012010)){
  j<-which(top20012010$Var1[i] == eoeoe$identifiant)
  z<-which(paste(eoeoe$Firstauthor[j],eoeoe$Datepubli[j],eoeoe$Issue[j],eoeoe$Page[j])==eoeoe$identifiant[j])[1]
  top20012010$V1[i] <- eoeoe$V1[j[z]]
}

for(i in 1:nrow(top20112020)){
  j<-which(top20112020$Var1[i] == eoeoe$identifiant)
  z<-which(paste(eoeoe$Firstauthor[j],eoeoe$Datepubli[j],eoeoe$Issue[j],eoeoe$Page[j])==eoeoe$identifiant[j])[1]
  top20112020$V1[i] <- eoeoe$V1[j[z]]
}



#### First

top19811990$authors<- str_extract_all(top19811990$V1, "(^.*\\, [[:alpha:]]\\.[[:alpha:]]\\.\\, )|(^.*\\, [[:alpha:]]\\.\\, )")
top19811990$authors<-as.character(top19811990$authors)
top19811990$authors2<- str_extract_all(top19811990$authors, "\\.\\, [A-z].*\\, .*\\.\\,")
top19811990$authors<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top19811990$authors)
top19811990$authors2<-as.character(top19811990$authors2)
top19811990$authors2<-str_replace(string = top19811990$authors2, pattern = "^\\.\\, ", replacement = "")
top19811990$authors3<- str_extract_all(top19811990$authors2, "\\.\\, [A-z].*\\, .*\\.\\,")
top19811990$authors2<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top19811990$authors2)
top19811990$authors3<-as.character(top19811990$authors3)
top19811990$authors3<-str_replace(string = top19811990$authors3, pattern = "^\\.\\, ", replacement = "")
top19811990$authors4<- str_extract_all(top19811990$authors3, "\\.\\, [A-z].*\\, .*\\.\\,")
top19811990$authors3<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top19811990$authors3)
top19811990$authors4<-as.character(top19811990$authors4)
top19811990$authors4<-str_replace(string = top19811990$authors4, pattern = "^\\.\\, ", replacement = "")
top19811990$authors5<- str_extract_all(top19811990$authors4, "\\.\\, [A-z].*\\, .*\\.\\,")
top19811990$authors4<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top19811990$authors4)
top19811990$authors5<-as.character(top19811990$authors5)
top19811990$authors5<-str_replace(string = top19811990$authors5, pattern = "^\\.\\, ", replacement = "")
top19811990$authors6<- str_extract_all(top19811990$authors5, "\\.\\, [A-z].*\\, .*\\.\\,")
top19811990$authors5<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top19811990$authors5)
top19811990$authors6<-as.character(top19811990$authors6)
top19811990$authors6<-str_replace(string = top19811990$authors6, pattern = "^\\.\\, ", replacement = "")
top19811990$authors7<- str_extract_all(top19811990$authors6, "\\.\\, [A-z].*\\, .*\\.\\,")
top19811990$authors6<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top19811990$authors6)
top19811990$authors7<-as.character(top19811990$authors7)
top19811990$authors7<-str_replace(string = top19811990$authors7, pattern = "^\\.\\, ", replacement = "")
top19811990$authors8<- str_extract_all(top19811990$authors7, "\\.\\, [A-z].*\\, .*\\.\\,")
top19811990$authors7<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top19811990$authors7)
top19811990$authors8<-as.character(top19811990$authors8)
top19811990$authors8<-str_replace(string = top19811990$authors8, pattern = "^\\.\\, ", replacement = "")
top19811990$authors9<- str_extract_all(top19811990$authors7, "\\.\\, [A-z].*\\, .*\\.\\,")
top19811990$authors8<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top19811990$authors8)
top19811990$authors9<-as.character(top19811990$authors9)
top19811990$authors9<-str_replace(string = top19811990$authors9, pattern = "^\\.\\, ", replacement = "")



top19811990$authors<-str_replace(string = top19811990$authors, pattern = "\\.\\, .*", replacement = "")
top19811990$authors2<-str_replace(string = top19811990$authors2, pattern = "\\.\\, .*", replacement = "")
top19811990$authors3<-str_replace(string = top19811990$authors3, pattern = "\\.\\, .*", replacement = "")
top19811990$authors4<-str_replace(string = top19811990$authors4, pattern = "\\.\\, .*", replacement = "")
top19811990$authors5<-str_replace(string = top19811990$authors5, pattern = "\\.\\, .*", replacement = "")
top19811990$authors6<-str_replace(string = top19811990$authors6, pattern = "\\.\\, .*", replacement = "")
top19811990$authors7<-str_replace(string = top19811990$authors7, pattern = "\\.\\, .*", replacement = "")
top19811990$authors8<-str_replace(string = top19811990$authors8, pattern = "\\.\\, .*", replacement = "")
top19811990$authors9<-str_replace(string = top19811990$authors9, pattern = "\\.\\, .*", replacement = "")


top19811990$authors[top19811990$authors == "character(0)"] <- "AB"
top19811990$authors2[top19811990$authors2 == "character(0)"] <- "AB"
top19811990$authors3[top19811990$authors3 == "character(0)"] <- "AB"
top19811990$authors4[top19811990$authors4 == "character(0)"] <- "AB"
top19811990$authors5[top19811990$authors5 == "character(0)"] <- "AB"
top19811990$authors6[top19811990$authors6 == "character(0)"] <- "AB"
top19811990$authors7[top19811990$authors7 == "character(0)"] <- "AB"
top19811990$authors8[top19811990$authors8 == "character(0)"] <- "AB"
top19811990$authors9[top19811990$authors9 == "character(0)"] <- "AB"


#### Second


top19912000$authors<- str_extract_all(top19912000$V1, "(^.*\\, [[:alpha:]]\\.[[:alpha:]]\\.\\, )|(^.*\\, [[:alpha:]]\\.\\, )")
top19912000$authors<-as.character(top19912000$authors)
top19912000$authors2<- str_extract_all(top19912000$authors, "\\.\\, [A-z].*\\, .*\\.\\,")
top19912000$authors<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top19912000$authors)
top19912000$authors2<-as.character(top19912000$authors2)
top19912000$authors2<-str_replace(string = top19912000$authors2, pattern = "^\\.\\, ", replacement = "")
top19912000$authors3<- str_extract_all(top19912000$authors2, "\\.\\, [A-z].*\\, .*\\.\\,")
top19912000$authors2<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top19912000$authors2)
top19912000$authors3<-as.character(top19912000$authors3)
top19912000$authors3<-str_replace(string = top19912000$authors3, pattern = "^\\.\\, ", replacement = "")
top19912000$authors4<- str_extract_all(top19912000$authors3, "\\.\\, [A-z].*\\, .*\\.\\,")
top19912000$authors3<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top19912000$authors3)
top19912000$authors4<-as.character(top19912000$authors4)
top19912000$authors4<-str_replace(string = top19912000$authors4, pattern = "^\\.\\, ", replacement = "")
top19912000$authors5<- str_extract_all(top19912000$authors4, "\\.\\, [A-z].*\\, .*\\.\\,")
top19912000$authors4<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top19912000$authors4)
top19912000$authors5<-as.character(top19912000$authors5)
top19912000$authors5<-str_replace(string = top19912000$authors5, pattern = "^\\.\\, ", replacement = "")
top19912000$authors6<- str_extract_all(top19912000$authors5, "\\.\\, [A-z].*\\, .*\\.\\,")
top19912000$authors5<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top19912000$authors5)
top19912000$authors6<-as.character(top19912000$authors6)
top19912000$authors6<-str_replace(string = top19912000$authors6, pattern = "^\\.\\, ", replacement = "")
top19912000$authors7<- str_extract_all(top19912000$authors6, "\\.\\, [A-z].*\\, .*\\.\\,")
top19912000$authors6<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top19912000$authors6)
top19912000$authors7<-as.character(top19912000$authors7)
top19912000$authors7<-str_replace(string = top19912000$authors7, pattern = "^\\.\\, ", replacement = "")
top19912000$authors8<- str_extract_all(top19912000$authors7, "\\.\\, [A-z].*\\, .*\\.\\,")
top19912000$authors7<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top19912000$authors7)
top19912000$authors8<-as.character(top19912000$authors8)
top19912000$authors8<-str_replace(string = top19912000$authors8, pattern = "^\\.\\, ", replacement = "")
top19912000$authors9<- str_extract_all(top19912000$authors7, "\\.\\, [A-z].*\\, .*\\.\\,")
top19912000$authors8<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top19912000$authors8)
top19912000$authors9<-as.character(top19912000$authors9)
top19912000$authors9<-str_replace(string = top19912000$authors9, pattern = "^\\.\\, ", replacement = "")



top19912000$authors<-str_replace(string = top19912000$authors, pattern = "\\.\\, .*", replacement = "")
top19912000$authors2<-str_replace(string = top19912000$authors2, pattern = "\\.\\, .*", replacement = "")
top19912000$authors3<-str_replace(string = top19912000$authors3, pattern = "\\.\\, .*", replacement = "")
top19912000$authors4<-str_replace(string = top19912000$authors4, pattern = "\\.\\, .*", replacement = "")
top19912000$authors5<-str_replace(string = top19912000$authors5, pattern = "\\.\\, .*", replacement = "")
top19912000$authors6<-str_replace(string = top19912000$authors6, pattern = "\\.\\, .*", replacement = "")
top19912000$authors7<-str_replace(string = top19912000$authors7, pattern = "\\.\\, .*", replacement = "")
top19912000$authors8<-str_replace(string = top19912000$authors8, pattern = "\\.\\, .*", replacement = "")
top19912000$authors9<-str_replace(string = top19912000$authors9, pattern = "\\.\\, .*", replacement = "")


top19912000$authors[top19912000$authors == "character(0)"] <- "AB"
top19912000$authors2[top19912000$authors2 == "character(0)"] <- "AB"
top19912000$authors3[top19912000$authors3 == "character(0)"] <- "AB"
top19912000$authors4[top19912000$authors4 == "character(0)"] <- "AB"
top19912000$authors5[top19912000$authors5 == "character(0)"] <- "AB"
top19912000$authors6[top19912000$authors6 == "character(0)"] <- "AB"
top19912000$authors7[top19912000$authors7 == "character(0)"] <- "AB"
top19912000$authors8[top19912000$authors8 == "character(0)"] <- "AB"
top19912000$authors9[top19912000$authors9 == "character(0)"] <- "AB"


# Third


top20012010$authors<- str_extract_all(top20012010$V1, "(^.*\\, [[:alpha:]]\\.[[:alpha:]]\\.\\, )|(^.*\\, [[:alpha:]]\\.\\, )")
top20012010$authors<-as.character(top20012010$authors)
top20012010$authors2<- str_extract_all(top20012010$authors, "\\.\\, [A-z].*\\, .*\\.\\,")
top20012010$authors<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top20012010$authors)
top20012010$authors2<-as.character(top20012010$authors2)
top20012010$authors2<-str_replace(string = top20012010$authors2, pattern = "^\\.\\, ", replacement = "")
top20012010$authors3<- str_extract_all(top20012010$authors2, "\\.\\, [A-z].*\\, .*\\.\\,")
top20012010$authors2<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top20012010$authors2)
top20012010$authors3<-as.character(top20012010$authors3)
top20012010$authors3<-str_replace(string = top20012010$authors3, pattern = "^\\.\\, ", replacement = "")
top20012010$authors4<- str_extract_all(top20012010$authors3, "\\.\\, [A-z].*\\, .*\\.\\,")
top20012010$authors3<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top20012010$authors3)
top20012010$authors4<-as.character(top20012010$authors4)
top20012010$authors4<-str_replace(string = top20012010$authors4, pattern = "^\\.\\, ", replacement = "")
top20012010$authors5<- str_extract_all(top20012010$authors4, "\\.\\, [A-z].*\\, .*\\.\\,")
top20012010$authors4<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top20012010$authors4)
top20012010$authors5<-as.character(top20012010$authors5)
top20012010$authors5<-str_replace(string = top20012010$authors5, pattern = "^\\.\\, ", replacement = "")
top20012010$authors6<- str_extract_all(top20012010$authors5, "\\.\\, [A-z].*\\, .*\\.\\,")
top20012010$authors5<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top20012010$authors5)
top20012010$authors6<-as.character(top20012010$authors6)
top20012010$authors6<-str_replace(string = top20012010$authors6, pattern = "^\\.\\, ", replacement = "")
top20012010$authors7<- str_extract_all(top20012010$authors6, "\\.\\, [A-z].*\\, .*\\.\\,")
top20012010$authors6<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top20012010$authors6)
top20012010$authors7<-as.character(top20012010$authors7)
top20012010$authors7<-str_replace(string = top20012010$authors7, pattern = "^\\.\\, ", replacement = "")
top20012010$authors8<- str_extract_all(top20012010$authors7, "\\.\\, [A-z].*\\, .*\\.\\,")
top20012010$authors7<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top20012010$authors7)
top20012010$authors8<-as.character(top20012010$authors8)
top20012010$authors8<-str_replace(string = top20012010$authors8, pattern = "^\\.\\, ", replacement = "")
top20012010$authors9<- str_extract_all(top20012010$authors7, "\\.\\, [A-z].*\\, .*\\.\\,")
top20012010$authors8<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top20012010$authors8)
top20012010$authors9<-as.character(top20012010$authors9)
top20012010$authors9<-str_replace(string = top20012010$authors9, pattern = "^\\.\\, ", replacement = "")



top20012010$authors<-str_replace(string = top20012010$authors, pattern = "\\.\\, .*", replacement = "")
top20012010$authors2<-str_replace(string = top20012010$authors2, pattern = "\\.\\, .*", replacement = "")
top20012010$authors3<-str_replace(string = top20012010$authors3, pattern = "\\.\\, .*", replacement = "")
top20012010$authors4<-str_replace(string = top20012010$authors4, pattern = "\\.\\, .*", replacement = "")
top20012010$authors5<-str_replace(string = top20012010$authors5, pattern = "\\.\\, .*", replacement = "")
top20012010$authors6<-str_replace(string = top20012010$authors6, pattern = "\\.\\, .*", replacement = "")
top20012010$authors7<-str_replace(string = top20012010$authors7, pattern = "\\.\\, .*", replacement = "")
top20012010$authors8<-str_replace(string = top20012010$authors8, pattern = "\\.\\, .*", replacement = "")
top20012010$authors9<-str_replace(string = top20012010$authors9, pattern = "\\.\\, .*", replacement = "")


top20012010$authors[top20012010$authors == "character(0)"] <- "AB"
top20012010$authors2[top20012010$authors2 == "character(0)"] <- "AB"
top20012010$authors3[top20012010$authors3 == "character(0)"] <- "AB"
top20012010$authors4[top20012010$authors4 == "character(0)"] <- "AB"
top20012010$authors5[top20012010$authors5 == "character(0)"] <- "AB"
top20012010$authors6[top20012010$authors6 == "character(0)"] <- "AB"
top20012010$authors7[top20012010$authors7 == "character(0)"] <- "AB"
top20012010$authors8[top20012010$authors8 == "character(0)"] <- "AB"
top20012010$authors9[top20012010$authors9 == "character(0)"] <- "AB"

## Fourth



top20112020$authors<- str_extract_all(top20112020$V1, "(^.*\\, [[:alpha:]]\\.[[:alpha:]]\\.\\, )|(^.*\\, [[:alpha:]]\\.\\, )")
top20112020$authors<-as.character(top20112020$authors)
top20112020$authors2<- str_extract_all(top20112020$authors, "\\.\\, [A-z].*\\, .*\\.\\,")
top20112020$authors<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top20112020$authors)
top20112020$authors2<-as.character(top20112020$authors2)
top20112020$authors2<-str_replace(string = top20112020$authors2, pattern = "^\\.\\, ", replacement = "")
top20112020$authors3<- str_extract_all(top20112020$authors2, "\\.\\, [A-z].*\\, .*\\.\\,")
top20112020$authors2<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top20112020$authors2)
top20112020$authors3<-as.character(top20112020$authors3)
top20112020$authors3<-str_replace(string = top20112020$authors3, pattern = "^\\.\\, ", replacement = "")
top20112020$authors4<- str_extract_all(top20112020$authors3, "\\.\\, [A-z].*\\, .*\\.\\,")
top20112020$authors3<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top20112020$authors3)
top20112020$authors4<-as.character(top20112020$authors4)
top20112020$authors4<-str_replace(string = top20112020$authors4, pattern = "^\\.\\, ", replacement = "")
top20112020$authors5<- str_extract_all(top20112020$authors4, "\\.\\, [A-z].*\\, .*\\.\\,")
top20112020$authors4<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top20112020$authors4)
top20112020$authors5<-as.character(top20112020$authors5)
top20112020$authors5<-str_replace(string = top20112020$authors5, pattern = "^\\.\\, ", replacement = "")
top20112020$authors6<- str_extract_all(top20112020$authors5, "\\.\\, [A-z].*\\, .*\\.\\,")
top20112020$authors5<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top20112020$authors5)
top20112020$authors6<-as.character(top20112020$authors6)
top20112020$authors6<-str_replace(string = top20112020$authors6, pattern = "^\\.\\, ", replacement = "")
top20112020$authors7<- str_extract_all(top20112020$authors6, "\\.\\, [A-z].*\\, .*\\.\\,")
top20112020$authors6<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top20112020$authors6)
top20112020$authors7<-as.character(top20112020$authors7)
top20112020$authors7<-str_replace(string = top20112020$authors7, pattern = "^\\.\\, ", replacement = "")
top20112020$authors8<- str_extract_all(top20112020$authors7, "\\.\\, [A-z].*\\, .*\\.\\,")
top20112020$authors7<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top20112020$authors7)
top20112020$authors8<-as.character(top20112020$authors8)
top20112020$authors8<-str_replace(string = top20112020$authors8, pattern = "^\\.\\, ", replacement = "")
top20112020$authors9<- str_extract_all(top20112020$authors7, "\\.\\, [A-z].*\\, .*\\.\\,")
top20112020$authors8<-gsub("\\.\\, [A-z].*\\, .*\\.\\,", "",top20112020$authors8)
top20112020$authors9<-as.character(top20112020$authors9)
top20112020$authors9<-str_replace(string = top20112020$authors9, pattern = "^\\.\\, ", replacement = "")



top20112020$authors<-str_replace(string = top20112020$authors, pattern = "\\.\\, .*", replacement = "")
top20112020$authors2<-str_replace(string = top20112020$authors2, pattern = "\\.\\, .*", replacement = "")
top20112020$authors3<-str_replace(string = top20112020$authors3, pattern = "\\.\\, .*", replacement = "")
top20112020$authors4<-str_replace(string = top20112020$authors4, pattern = "\\.\\, .*", replacement = "")
top20112020$authors5<-str_replace(string = top20112020$authors5, pattern = "\\.\\, .*", replacement = "")
top20112020$authors6<-str_replace(string = top20112020$authors6, pattern = "\\.\\, .*", replacement = "")
top20112020$authors7<-str_replace(string = top20112020$authors7, pattern = "\\.\\, .*", replacement = "")
top20112020$authors8<-str_replace(string = top20112020$authors8, pattern = "\\.\\, .*", replacement = "")
top20112020$authors9<-str_replace(string = top20112020$authors9, pattern = "\\.\\, .*", replacement = "")


top20112020$authors[top20112020$authors == "character(0)"] <- "AB"
top20112020$authors2[top20112020$authors2 == "character(0)"] <- "AB"
top20112020$authors3[top20112020$authors3 == "character(0)"] <- "AB"
top20112020$authors4[top20112020$authors4 == "character(0)"] <- "AB"
top20112020$authors5[top20112020$authors5 == "character(0)"] <- "AB"
top20112020$authors6[top20112020$authors6 == "character(0)"] <- "AB"
top20112020$authors7[top20112020$authors7 == "character(0)"] <- "AB"
top20112020$authors8[top20112020$authors8 == "character(0)"] <- "AB"
top20112020$authors9[top20112020$authors9 == "character(0)"] <- "AB"



##### First


top19811990 <- na.omit(top19811990)

top19811990 <- top19811990[rep(row.names(top19811990), ifelse(top19811990$authors9!="AB",9,ifelse(top19811990$authors8!="AB",8,ifelse(top19811990$authors7!="AB",7,ifelse(top19811990$authors6!="AB",6,ifelse(top19811990$authors5!="AB",5,ifelse(top19811990$authors4!="AB",4,ifelse(top19811990$authors3!="AB",3,ifelse(top19811990$authors2!="AB",2,1))))))))),]



for(i in 1:(nrow(top19811990)-1)){if(top19811990[i,3]==top19811990[i+1,3]){
  top19811990[i+1,4]<-top19811990[i+1,5]
}else{top19811990[i+1,4]<-top19811990[i+1,4]}}


for(i in 1:(nrow(top19811990)-2)){if(top19811990[i,3]==top19811990[i+2,3]){
  top19811990[i+2,4]<-top19811990[i,6]
}else{top19811990[i+2,4]<-top19811990[i+2,4]}}

for(i in 1:(nrow(top19811990)-3)){if(top19811990[i,3]==top19811990[i+3,3]){
  top19811990[i+3,4]<-top19811990[i,7]
}else{top19811990[i+3,4]<-top19811990[i+3,4]}}


for(i in 1:(nrow(top19811990)-4)){if(top19811990[i,3]==top19811990[i+4,3]){
  top19811990[i+4,4]<-top19811990[i,8]
}else{top19811990[i+4,4]<-top19811990[i+4,4]}}


for(i in 1:(nrow(top19811990)-5)){if(top19811990[i,3]==top19811990[i+5,3]){
  top19811990[i+5,4]<-top19811990[i,9]
}else{top19811990[i+5,4]<-top19811990[i+5,4]}}


for(i in 1:(nrow(top19811990)-6)){if(top19811990[i,3]==top19811990[i+6,3]){
  top19811990[i+6,4]<-top19811990[i,10]
}else{top19811990[i+6,4]<-top19811990[i+6,4]}}



for(i in 1:(nrow(top19811990)-7)){if(top19811990[i,3]==top19811990[i+7,3]){
  top19811990[i+7,4]<-top19811990[i,11]
}else{top19811990[i+7,4]<-top19811990[i+7,4]}}


for(i in 1:(nrow(top19811990)-8)){if(top19811990[i,3]==top19811990[i+8,3]){
  top19811990[i+8,4]<-top19811990[i,12]
}else{top19811990[i+8,4]<-top19811990[i+8,4]}}



top19811990<-top19811990[,c(2,3,4)]



top19811990$authors<-str_replace(string = top19811990$authors, pattern = "\\,$", replacement = "")
top19811990$authors<-str_replace(string = top19811990$authors, pattern = "\\.$", replacement = "")

top19811990$authors<-iconv(top19811990$authors,from="UTF-8",to="ASCII//TRANSLIT")

##### On passe les noms en majuscule

top19811990$authors<-toupper(top19811990$authors)

top19811990$authors<-trimws(top19811990$authors)




###### Second



top19912000 <- na.omit(top19912000)

top19912000 <- top19912000[rep(row.names(top19912000), ifelse(top19912000$authors9!="AB",9,ifelse(top19912000$authors8!="AB",8,ifelse(top19912000$authors7!="AB",7,ifelse(top19912000$authors6!="AB",6,ifelse(top19912000$authors5!="AB",5,ifelse(top19912000$authors4!="AB",4,ifelse(top19912000$authors3!="AB",3,ifelse(top19912000$authors2!="AB",2,1))))))))),]



for(i in 1:(nrow(top19912000)-1)){if(top19912000[i,3]==top19912000[i+1,3]){
  top19912000[i+1,4]<-top19912000[i+1,5]
}else{top19912000[i+1,4]<-top19912000[i+1,4]}}


for(i in 1:(nrow(top19912000)-2)){if(top19912000[i,3]==top19912000[i+2,3]){
  top19912000[i+2,4]<-top19912000[i,6]
}else{top19912000[i+2,4]<-top19912000[i+2,4]}}

for(i in 1:(nrow(top19912000)-3)){if(top19912000[i,3]==top19912000[i+3,3]){
  top19912000[i+3,4]<-top19912000[i,7]
}else{top19912000[i+3,4]<-top19912000[i+3,4]}}


for(i in 1:(nrow(top19912000)-4)){if(top19912000[i,3]==top19912000[i+4,3]){
  top19912000[i+4,4]<-top19912000[i,8]
}else{top19912000[i+4,4]<-top19912000[i+4,4]}}


for(i in 1:(nrow(top19912000)-5)){if(top19912000[i,3]==top19912000[i+5,3]){
  top19912000[i+5,4]<-top19912000[i,9]
}else{top19912000[i+5,4]<-top19912000[i+5,4]}}


for(i in 1:(nrow(top19912000)-6)){if(top19912000[i,3]==top19912000[i+6,3]){
  top19912000[i+6,4]<-top19912000[i,10]
}else{top19912000[i+6,4]<-top19912000[i+6,4]}}



for(i in 1:(nrow(top19912000)-7)){if(top19912000[i,3]==top19912000[i+7,3]){
  top19912000[i+7,4]<-top19912000[i,11]
}else{top19912000[i+7,4]<-top19912000[i+7,4]}}


for(i in 1:(nrow(top19912000)-8)){if(top19912000[i,3]==top19912000[i+8,3]){
  top19912000[i+8,4]<-top19912000[i,12]
}else{top19912000[i+8,4]<-top19912000[i+8,4]}}



top19912000<-top19912000[,c(2,3,4)]



top19912000$authors<-str_replace(string = top19912000$authors, pattern = "\\,$", replacement = "")
top19912000$authors<-str_replace(string = top19912000$authors, pattern = "\\.$", replacement = "")

top19912000$authors<-iconv(top19912000$authors,from="UTF-8",to="ASCII//TRANSLIT")

##### On passe les noms en majuscule

top19912000$authors<-toupper(top19912000$authors)

top19912000$authors<-trimws(top19912000$authors)



###### Third


top20012010 <- na.omit(top20012010)

top20012010 <- top20012010[rep(row.names(top20012010), ifelse(top20012010$authors9!="AB",9,ifelse(top20012010$authors8!="AB",8,ifelse(top20012010$authors7!="AB",7,ifelse(top20012010$authors6!="AB",6,ifelse(top20012010$authors5!="AB",5,ifelse(top20012010$authors4!="AB",4,ifelse(top20012010$authors3!="AB",3,ifelse(top20012010$authors2!="AB",2,1))))))))),]



for(i in 1:(nrow(top20012010)-1)){if(top20012010[i,3]==top20012010[i+1,3]){
  top20012010[i+1,4]<-top20012010[i+1,5]
}else{top20012010[i+1,4]<-top20012010[i+1,4]}}


for(i in 1:(nrow(top20012010)-2)){if(top20012010[i,3]==top20012010[i+2,3]){
  top20012010[i+2,4]<-top20012010[i,6]
}else{top20012010[i+2,4]<-top20012010[i+2,4]}}

for(i in 1:(nrow(top20012010)-3)){if(top20012010[i,3]==top20012010[i+3,3]){
  top20012010[i+3,4]<-top20012010[i,7]
}else{top20012010[i+3,4]<-top20012010[i+3,4]}}


for(i in 1:(nrow(top20012010)-4)){if(top20012010[i,3]==top20012010[i+4,3]){
  top20012010[i+4,4]<-top20012010[i,8]
}else{top20012010[i+4,4]<-top20012010[i+4,4]}}


for(i in 1:(nrow(top20012010)-5)){if(top20012010[i,3]==top20012010[i+5,3]){
  top20012010[i+5,4]<-top20012010[i,9]
}else{top20012010[i+5,4]<-top20012010[i+5,4]}}


for(i in 1:(nrow(top20012010)-6)){if(top20012010[i,3]==top20012010[i+6,3]){
  top20012010[i+6,4]<-top20012010[i,10]
}else{top20012010[i+6,4]<-top20012010[i+6,4]}}



for(i in 1:(nrow(top20012010)-7)){if(top20012010[i,3]==top20012010[i+7,3]){
  top20012010[i+7,4]<-top20012010[i,11]
}else{top20012010[i+7,4]<-top20012010[i+7,4]}}


for(i in 1:(nrow(top20012010)-8)){if(top20012010[i,3]==top20012010[i+8,3]){
  top20012010[i+8,4]<-top20012010[i,12]
}else{top20012010[i+8,4]<-top20012010[i+8,4]}}



top20012010<-top20012010[,c(2,3,4)]



top20012010$authors<-str_replace(string = top20012010$authors, pattern = "\\,$", replacement = "")
top20012010$authors<-str_replace(string = top20012010$authors, pattern = "\\.$", replacement = "")

top20012010$authors<-iconv(top20012010$authors,from="UTF-8",to="ASCII//TRANSLIT")

##### On passe les noms en majuscule

top20012010$authors<-toupper(top20012010$authors)

top20012010$authors<-trimws(top20012010$authors)




###### Fourth




top20112020 <- na.omit(top20112020)

top20112020 <- top20112020[rep(row.names(top20112020), ifelse(top20112020$authors9!="AB",9,ifelse(top20112020$authors8!="AB",8,ifelse(top20112020$authors7!="AB",7,ifelse(top20112020$authors6!="AB",6,ifelse(top20112020$authors5!="AB",5,ifelse(top20112020$authors4!="AB",4,ifelse(top20112020$authors3!="AB",3,ifelse(top20112020$authors2!="AB",2,1))))))))),]



for(i in 1:(nrow(top20112020)-1)){if(top20112020[i,3]==top20112020[i+1,3]){
  top20112020[i+1,4]<-top20112020[i+1,5]
}else{top20112020[i+1,4]<-top20112020[i+1,4]}}


for(i in 1:(nrow(top20112020)-2)){if(top20112020[i,3]==top20112020[i+2,3]){
  top20112020[i+2,4]<-top20112020[i,6]
}else{top20112020[i+2,4]<-top20112020[i+2,4]}}

for(i in 1:(nrow(top20112020)-3)){if(top20112020[i,3]==top20112020[i+3,3]){
  top20112020[i+3,4]<-top20112020[i,7]
}else{top20112020[i+3,4]<-top20112020[i+3,4]}}


for(i in 1:(nrow(top20112020)-4)){if(top20112020[i,3]==top20112020[i+4,3]){
  top20112020[i+4,4]<-top20112020[i,8]
}else{top20112020[i+4,4]<-top20112020[i+4,4]}}


for(i in 1:(nrow(top20112020)-5)){if(top20112020[i,3]==top20112020[i+5,3]){
  top20112020[i+5,4]<-top20112020[i,9]
}else{top20112020[i+5,4]<-top20112020[i+5,4]}}


for(i in 1:(nrow(top20112020)-6)){if(top20112020[i,3]==top20112020[i+6,3]){
  top20112020[i+6,4]<-top20112020[i,10]
}else{top20112020[i+6,4]<-top20112020[i+6,4]}}



for(i in 1:(nrow(top20112020)-7)){if(top20112020[i,3]==top20112020[i+7,3]){
  top20112020[i+7,4]<-top20112020[i,11]
}else{top20112020[i+7,4]<-top20112020[i+7,4]}}


for(i in 1:(nrow(top20112020)-8)){if(top20112020[i,3]==top20112020[i+8,3]){
  top20112020[i+8,4]<-top20112020[i,12]
}else{top20112020[i+8,4]<-top20112020[i+8,4]}}



top20112020<-top20112020[,c(2,3,4)]



top20112020$authors<-str_replace(string = top20112020$authors, pattern = "\\,$", replacement = "")
top20112020$authors<-str_replace(string = top20112020$authors, pattern = "\\.$", replacement = "")

top20112020$authors<-iconv(top20112020$authors,from="UTF-8",to="ASCII//TRANSLIT")

##### On passe les noms en majuscule

top20112020$authors<-toupper(top20112020$authors)

top20112020$authors<-trimws(top20112020$authors)






freqauth119811990<-table(top19811990$authors)
freqauth119811990<-as.data.frame(freqauth119811990)

freqauth119912000<-table(top19912000$authors)
freqauth119912000<-as.data.frame(freqauth119912000)

freqauth120012010<-table(top20012010$authors)
freqauth120012010<-as.data.frame(freqauth120012010)

freqauth120112020<-table(top20112020$authors)
freqauth120112020<-as.data.frame(freqauth120112020)


library(questionr)



freqauth19811990<-wtd.table(x = top19811990$authors, weights = top19811990$Freq)
freqauth19811990<-as.data.frame(freqauth19811990)

freqauth19912000<-wtd.table(x = top19912000$authors, weights = top19912000$Freq)
freqauth19912000<-as.data.frame(freqauth19912000)

freqauth20012010<-wtd.table(x = top20012010$authors, weights = top20012010$Freq)
freqauth20012010<-as.data.frame(freqauth20012010)

freqauth20112020<-wtd.table(x = top20112020$authors, weights = top20112020$Freq)
freqauth20112020<-as.data.frame(freqauth20112020)




auth19811990<-merge(freqauth119811990,freqauth19811990, by="Var1")
auth19912000<-merge(freqauth119912000,freqauth19912000, by="Var1")
auth20012010<-merge(freqauth120012010,freqauth20012010, by="Var1")
auth20112020<-merge(freqauth120112020,freqauth20112020, by="Var1")



names(auth19811990)[names(auth19811990) == "Var1"] <- "Name"
names(auth19811990)[names(auth19811990) == "Freq.x"] <- "Number of Ocurrences"
names(auth19811990)[names(auth19811990) == "Freq.y"] <- "Items"


names(auth19912000)[names(auth19912000) == "Var1"] <- "Name"
names(auth19912000)[names(auth19912000) == "Freq.x"] <- "Number of Ocurrences"
names(auth19912000)[names(auth19912000) == "Freq.y"] <- "Items"


names(auth20012010)[names(auth20012010) == "Var1"] <- "Name"
names(auth20012010)[names(auth20012010) == "Freq.x"] <- "Number of Ocurrences"
names(auth20012010)[names(auth20012010) == "Freq.y"] <- "Items"


names(auth20112020)[names(auth20112020) == "Var1"] <- "Name"
names(auth20112020)[names(auth20112020) == "Freq.x"] <- "Number of Ocurrences"
names(auth20112020)[names(auth20112020) == "Freq.y"] <- "Items"



auth19811990<-auth19811990[rev(order(auth19811990$`Number of Ocurrences`)),]
auth19912000<-auth19912000[rev(order(auth19912000$`Number of Ocurrences`)),]
auth20012010<-auth20012010[rev(order(auth20012010$`Number of Ocurrences`)),]
auth20112020<-auth20112020[rev(order(auth20112020$`Number of Ocurrences`)),]


auth19811990$intrus<-auth19811990$Name=="AB"
auth19912000$intrus<-auth19912000$Name=="AB"
auth20012010$intrus<-auth20012010$Name=="AB"
auth20112020$intrus<-auth20112020$Name=="AB"



auth19811990<-auth19811990[auth19811990$intrus==F,]
auth19811990<-auth19811990[1:25,]
auth19811990<-auth19811990[,c(1:3)]


auth19912000<-auth19912000[auth19912000$intrus==F,]
auth19912000<-auth19912000[1:25,]
auth19912000<-auth19912000[,c(1:3)]


auth20012010<-auth20012010[auth20012010$intrus==F,]
auth20012010<-auth20012010[1:25,]
auth20012010<-auth20012010[,c(1:3)]


auth20112020<-auth20112020[auth20112020$intrus==F,]
auth20112020<-auth20112020[1:25,]
auth20112020<-auth20112020[,c(1:3)]


auth19811990$YEAR<-"1981-1990"
auth19912000$YEAR<-"1991-2000"
auth20012010$YEAR<-"2001-2010"
auth20112020$YEAR<-"2011-2020"


auth19811990$`Number of Ocurrences`<-1:nrow(auth19811990)
auth19912000$`Number of Ocurrences`<-1:nrow(auth19912000)
auth20012010$`Number of Ocurrences`<-1:nrow(auth20012010)
auth20112020$`Number of Ocurrences`<-1:nrow(auth20112020)


auth19811990<-auth19811990[,c(1)]
auth19912000<-auth19912000[,c(1)]
auth20012010<-auth20012010[,c(1)]
auth20112020<-auth20112020[,c(1)]



auth19811990<-as.data.frame(auth19811990)
auth19912000<-as.data.frame(auth19912000)
auth20012010<-as.data.frame(auth20012010)
auth20112020<-as.data.frame(auth20112020)


names(auth19811990)[names(auth19811990) == "auth19811990"] <- "1980-1989"
names(auth19912000)[names(auth19912000) == "auth19912000"] <- "1990-1999"
names(auth20012010)[names(auth20012010) == "auth20012010"] <- "2000-2009"
names(auth20112020)[names(auth20112020) == "auth20112020"] <- "2010-2019"


auth19811990$`1980-1989`<-as.character(auth19811990$`1980-1989`)
auth19912000$`1990-1999`<-as.character(auth19912000$`1990-1999`)
auth20012010$`2000-2009`<-as.character(auth20012010$`2000-2009`)
auth20112020$`2010-2019`<-as.character(auth20112020$`2010-2019`)



#for(i in 1:nrow(auth19811990)){
#  auth19811990$`1980-1989`[i]<-paste(i,"-",auth19811990$`1980-1989`[i])
#}

#for(i in 1:nrow(auth19912000)){
#  auth19912000$`1990-1999`[i]<-paste(i,"-",auth19912000$`1990-1999`[i])
#}

#for(i in 1:nrow(auth20012010)){
#  auth20012010$`2000-2009`[i]<-paste(i,"-",auth20012010$`2000-2009`[i])
#}


#for(i in 1:nrow(auth20112020)){
#  auth20112020$`2010-2019`[i]<-paste(i,"-",auth20112020$`2010-2019`[i])
#}

Rank<-1:nrow(auth19811990)

authy<-cbind(Rank,auth19811990,auth19912000,auth20012010,auth20112020)





library(knitr)
library(kableExtra)

authy %>%
  kbl() %>%
  kable_styling()
Rank 1980-1989 1990-1999 2000-2009 2010-2019
1 SCHMALENSEE, R SHAPIRO, C TIROLE, J SARKIS, J
2 WEISS, L.W TEECE, D.J ZEITHAML, V.A CASADESUS, M
3 SILBERER, G SCHMALENSEE, R SHAPIRO, C TIROLE, J
4 STIGLITZ, J FARRELL, J SCHROEDER, R.G ZHU, Q
5 RAFFEE, H ZEITHAML, V.A BERRY, L.L SCHROEDER, R.G
6 CAVES, R.E BERRY, L.L OLIVER, R.L MILGROM, P
7 SLOVIC, P SALONER, G MILGROM, P KARAPETROVIC, S
8 MILGROM, P STIGLITZ, J.E PARASURAMAN, A FEENSTRA, R.C
9 FRITZ, W PARASURAMAN, A PAKES, A HERAS, I
10 FEENSTRA, R.C PAKES, A FARRELL, J HELPMAN, E
11 WILSON, R OLIVER, R.L SCHMALENSEE, R SHAPIRO, C
12 SPENCE, A.M ECONOMIDES, N FUDENBERG, D MAYER, T
13 PORTER, M.E WERNERFELT, B FLYNN, B.B CHEN, Y
14 MASKIN, E TIROLE, J REARDON, T WOOLDRIDGE, J.M
15 LICHTENSTEIN, S PORTER, M.E PRAKASH, A VAN WASSENHOVE, L.N
16 JURAN, J.M MILGROM, P RUST, R.T PRAKASH, A
17 WOLINSKY, A FORNELL, C HELPMAN, E HENSON, S
18 TIROLE, J WOLINSKY, A GANDAL, N BLIND, K
19 SOBEL, J WILSON, R FEENSTRA, R.C ZEITHAML, V.A
20 SALOP, S WILLIAMSON, O.E CORBETT, C.J LAI, K.H
21 ROBERTS, J TVERSKY, A SHLEIFER, A EATON, J
22 GEROSKI, P.A SUTTON, J ZHU, Q DARNALL, N
23 FARRELL, J ROBERTS, J SOHAL, A.S ZHAO, X
24 DIXIT, A HECKMAN, J ROBERTS, J XIE, J
25 WILDE, L.L VIVES, X RABIN, M ROBERTS, M.J

2.2- Bump Chart

auth19811990<-merge(freqauth119811990,freqauth19811990, by="Var1")
auth19912000<-merge(freqauth119912000,freqauth19912000, by="Var1")
auth20012010<-merge(freqauth120012010,freqauth20012010, by="Var1")
auth20112020<-merge(freqauth120112020,freqauth20112020, by="Var1")



names(auth19811990)[names(auth19811990) == "Var1"] <- "Name"
names(auth19811990)[names(auth19811990) == "Freq.x"] <- "Number of Ocurrences"
names(auth19811990)[names(auth19811990) == "Freq.y"] <- "Items"


names(auth19912000)[names(auth19912000) == "Var1"] <- "Name"
names(auth19912000)[names(auth19912000) == "Freq.x"] <- "Number of Ocurrences"
names(auth19912000)[names(auth19912000) == "Freq.y"] <- "Items"


names(auth20012010)[names(auth20012010) == "Var1"] <- "Name"
names(auth20012010)[names(auth20012010) == "Freq.x"] <- "Number of Ocurrences"
names(auth20012010)[names(auth20012010) == "Freq.y"] <- "Items"


names(auth20112020)[names(auth20112020) == "Var1"] <- "Name"
names(auth20112020)[names(auth20112020) == "Freq.x"] <- "Number of Ocurrences"
names(auth20112020)[names(auth20112020) == "Freq.y"] <- "Items"



auth19811990<-auth19811990[rev(order(auth19811990$`Number of Ocurrences`)),]
auth19912000<-auth19912000[rev(order(auth19912000$`Number of Ocurrences`)),]
auth20012010<-auth20012010[rev(order(auth20012010$`Number of Ocurrences`)),]
auth20112020<-auth20112020[rev(order(auth20112020$`Number of Ocurrences`)),]


auth19811990$intrus<-auth19811990$Name=="AB"
auth19912000$intrus<-auth19912000$Name=="AB"
auth20012010$intrus<-auth20012010$Name=="AB"
auth20112020$intrus<-auth20112020$Name=="AB"



auth19811990<-auth19811990[auth19811990$intrus==F,]
auth19811990<-auth19811990[1:25,]
auth19811990<-auth19811990[,c(1:3)]


auth19912000<-auth19912000[auth19912000$intrus==F,]
auth19912000<-auth19912000[1:25,]
auth19912000<-auth19912000[,c(1:3)]


auth20012010<-auth20012010[auth20012010$intrus==F,]
auth20012010<-auth20012010[1:25,]
auth20012010<-auth20012010[,c(1:3)]


auth20112020<-auth20112020[auth20112020$intrus==F,]
auth20112020<-auth20112020[1:25,]
auth20112020<-auth20112020[,c(1:3)]


auth19811990$YEAR<-"1981-1990"
auth19912000$YEAR<-"1991-2000"
auth20012010$YEAR<-"2001-2010"
auth20112020$YEAR<-"2011-2020"


auth19811990$`Number of Ocurrences`<-1:nrow(auth19811990)
auth19912000$`Number of Ocurrences`<-1:nrow(auth19912000)
auth20012010$`Number of Ocurrences`<-1:nrow(auth20012010)
auth20112020$`Number of Ocurrences`<-1:nrow(auth20112020)


auth<-rbind(auth19811990,auth19912000,auth20012010,auth20112020)


library(ggplot2)
library(dplyr)






my_theme <- function() {
  
  # Colors
  color.background = "white"
  color.text = "#22211d"
  
  # Begin construction of chart
  theme_bw(base_size=15) +
    
    # Format background colors
    theme(panel.background = element_rect(fill=color.background,
                                          color=color.background)) +
    theme(plot.background  = element_rect(fill=color.background,
                                          color=color.background)) +
    theme(panel.border     = element_rect(color=color.background)) +
    theme(strip.background = element_rect(fill=color.background,
                                          color=color.background)) +
    
    # Format the grid
    theme(panel.grid.major.y = element_blank()) +
    theme(panel.grid.minor.y = element_blank()) +
    theme(axis.ticks       = element_blank()) +
    
    # Format the legend
    theme(legend.position = "none") +
    
    # Format title and axis labels
    theme(plot.title       = element_text(color=color.text, size=5, face = "bold")) +
    theme(axis.title.x     = element_text(size=0, color="black", face = "bold")) +
    theme(axis.title.y     = element_text(size=0, color="black", face = "bold",
                                          vjust=1.25)) +
    theme(axis.text.x      = element_text(size=0, vjust=0.5, hjust=0.5,
                                          color = color.text)) +
    ### Taille des nombre
    theme(axis.text.y      = element_text(size=2.5, color = color.text)) +
    theme(strip.text       = element_text(face = "bold")) +
    
    # Plot margins
    # Contour du graphique
    theme(plot.margin = unit(c(0, 0.2, 0.3, 0), "cm"))
}




library(ggiraph)



gg_point=ggplot(auth,aes(x = as.factor(YEAR), y = `Number of Ocurrences`, group = Name)) +
  # Taille des lignes
  geom_line_interactive(aes(color = Name, alpha = 1,tooltip=Name, data_id = Name), size = 0.3) +
  # Taille des points
  geom_point_interactive(aes(x = as.factor(YEAR), y = `Number of Ocurrences`, group = Name, color = Name, alpha = 1,tooltip = Name, data_id = Name), size = 1) +
  geom_point_interactive(color = "#FFFFFF", size = 0.01) +
  scale_y_reverse(breaks = 1:table(auth$YEAR)[[1]]) + 
  scale_x_discrete(breaks = 1:length(table(auth$YEAR))) +
  theme(legend.position = 'none') +
  # le x designe le positionnement des auteurs à gauche
  geom_text(data = auth %>% filter(YEAR == "1981-1990"),
            aes(label = Name, x = 0.42) , hjust = 0.0,
            fontface = "bold", color = "#888888", size = 0.7) +
  # idem mais à droite
  geom_text(data = auth %>% filter(YEAR == "2011-2020"),
            aes(label = Name, x = 4.5) , hjust = 1.0,
            fontface = "bold", color = "#888888", size = 0.7) +
  labs(x = '', y = '', title = 'Most quoted authors (1980-1989, 1990-1999, 2000-2009, 2010-2019)') +
  my_theme() 




girafe(ggobj = gg_point, width_svg = 3, height_svg = 2,
       options = list(
         opts_hover_inv(css = "opacity:0.1;"),
         opts_hover(css = "stroke-width:2;")
       ))

3- Bibliographic coupling 2010-2019

##### On a une colonne d'identifiant unique des articles et une colonne avec les refs biblios
##### recodées, on peut donc soumettre ça au package d'Aurelien

set.seed(12)


setwd("C:/Users/jgrad/Desktop/Network_Quality/Network_Quality")

load("Data_5_nodes.rda")
load("Data_7_finalbase.rda")

library(readr)
library(stringr)
#library(bibliometrix)
library(tidyverse)
library(biblionetwork)
#library(devtools)
#devtools::install_github("agoutsmedt/biblionetwork")


eoeoe2<-eoeoe

simple<-unique(eoeoe2$V2)
simple<-as.data.frame(simple)

#setdiff(desco$Cartel,simple[,1])

desco<-desco[desco$Cartel!=108237,]


comp<-cbind(simple,desco$Cartel)




desco$sloubi<-str_detect (string = desco$Datepubli, pattern = "2010|2011|2012|2013|2014|2015|2016|2017|2018|2019")
#desco$sloubi<-str_detect (string = desco$Datepubli, pattern = "1970|1971|1972|1973|1974|1975|1976|1977|1978|1979|1980|1981|1982|1983|1984|1985|1986|1987|1988|1989|1990|1991|1992|1993|1994|1995|1996|1997|1998|1990|2000")

desco<-desco[desco$sloubi==T,]


Cartel<-desco$Cartel

eoeoe2$toofar<-"AB"
for(i in 1:nrow(eoeoe2)){
  if(eoeoe2$V2[i]%in%Cartel){eoeoe2$toofar[i]<-T}else{eoeoe2$toofar[i]<-F}}

eoeoe2<-eoeoe2[eoeoe2$toofar==T,]

Carlito<-unique(eoeoe2$V2)

Carlito<-as.data.frame(Carlito)
Cartel<-as.data.frame(Cartel)


Cabal<-cbind(Carlito,Cartel)


eoeoe2$V2<-as.character(eoeoe2$V2)
eoeoe2$identifiant<-as.character(eoeoe2$identifiant)
desco$Cartel<-as.character(desco$Cartel)



Basefinale<-biblio_coupling(eoeoe2, source = "V2", ref = "identifiant", normalized_weight_only = FALSE, weight_threshold = 2)



#devtools::install_github("agoutsmedt/networkflow")

library(biblionetwork)
library(magrittr)
library(dplyr)
library(tidygraph)
library(networkflow)
library(tidygraph)
#devtools::install_github("ParkerICI/vite")
library(vite)




Edges_coupling2<-Basefinale[,-c(4)]


Nodes_coupling2<-desco

Nodes_coupling2$frequence<-1

Nodes_coupling2$Datepubli<-as.character(Nodes_coupling2$Datepubli)

Nodes_coupling2$author_date<-paste(Nodes_coupling2$Cartel,Nodes_coupling2$Firstauthor,Nodes_coupling2$Datepubli)

palette <- c("#1969B3","#01A5D8","#DA3E61","#3CB95F","#E0AF0C","#E25920","#6C7FC9","#DE9493","#CD242E","#6F4288","#B2EEF8","#7FF6FD","#FDB8D6","#8BF9A9","#FEF34A","#FEC57D","#DAEFFB","#FEE3E1","#FBB2A7","#EFD7F2","#5CAADA","#37D4F5","#F5779B","#62E186","#FBDA28","#FB8F4A","#A4B9EA","#FAC2C0","#EB6466","#AD87BC","#0B3074","#00517C","#871B2A","#1A6029","#7C4B05","#8A260E","#2E3679","#793F3F","#840F14","#401C56","#003C65","#741A09","#602A2A","#34134A","#114A1B","#27DDD1","#27DD8D","#4ADD27","#D3DD27","#DDA427","#DF2935","#DD27BC","#BA27DD","#3227DD","#2761DD","#27DDD1")

graph <- tbl_main_component(nodes = Nodes_coupling2, edges = Edges_coupling2, directed = FALSE, node_key = "Cartel", nb_components = 1)

graph <- leiden_workflow(graph, res_1 = 1)

graph <- community_colors(graph, palette, community_column = "Com_ID")


graph <- graph %>%
  activate(nodes) %>%
  mutate(degree = centrality_degree())



graph <- community_names(graph, ordering_column = "degree", naming = "author_date", community_column = "Com_ID")


graph <- graph %>%
  activate(nodes) %>% 
  mutate(size = degree) # use here what you will use for the size of the nodes in the graph. Force Atlas will take care of avoiding overlapping

graph <- vite::complete_forceatlas2(graph, first.iter = 10000, overlap.method = "repel", overlap.iter = 1000)
## Total number of iterations: 10000
## Total number of iterations: 1000
graph123<-as.data.frame(graph)



#################################################################################################################
#################################################################################################################
# On extrait les abstracts pour faire de l'analyse textuelle ---------------------------------
#################################################################################################################
#################################################################################################################


load("Data_4_Abstracts.rda")



zalerit$comcitant<-0
for(i in 1:nrow(graph123)){
  j<-which(zalerit$Cartel == graph123$Id[i])
  zalerit$comcitant[j]<-graph123$Com_ID[i]
}


library(dplyr)
library(janeaustenr) #Inutile je pense
library(tidytext)
library(gutenbergr)  #Idem
library(pdftools)
library(tidyverse)
library(qdapRegex)


zaler2<-zalerit[,c(1,3)]

zaler2<-zaler2[zaler2$comcitant!=0,]

zaler2$V1<-as.character(zaler2$V1)
zaler2$comcitant<-as.character(zaler2$comcitant)



paly<-length(table(zaler2$comcitant))


Basetotale_words <- zaler2 %>%
  unnest_tokens(word, V1) %>%
  count(comcitant, word, sort = TRUE)



# On supprime les mots de deux lettres et de une lettre
Basetotale_words$word<-rm_nchar_words(Basetotale_words$word, 2)
Basetotale_words$word<-rm_nchar_words(Basetotale_words$word, 1)


# On remplace le vide que cree l'etape precedente par des NA et on supprime les NA
Basetotale_words$word[Basetotale_words$word==""] <- NA
Basetotale_words <- na.omit(Basetotale_words)


mystopwords <- tibble(word = c("qmi","consumerswho"))


Basetotale_words <- anti_join(Basetotale_words, mystopwords,
                              by = "word")


plot_Basetotale <- Basetotale_words %>%
  bind_tf_idf(word, comcitant, n) %>%
  mutate(word = str_remove_all(word, "_")) %>%
  group_by(comcitant) %>%
  slice_max(tf_idf, n = 25) %>%
  ungroup() %>%
  mutate(word = reorder_within(word, tf_idf, comcitant)) %>%
  mutate(comcitant = factor(comcitant))



palette <- c("#1969B3","#01A5D8","#DA3E61","#3CB95F","#E0AF0C","#E25920","#6C7FC9","#DE9493","#CD242E","#6F4288","#B2EEF8","#7FF6FD","#FDB8D6","#8BF9A9","#FEF34A","#FEC57D","#DAEFFB","#FEE3E1","#FBB2A7","#EFD7F2","#5CAADA","#37D4F5","#F5779B","#62E186","#FBDA28","#FB8F4A","#A4B9EA","#FAC2C0","#EB6466","#AD87BC","#0B3074","#00517C","#871B2A","#1A6029","#7C4B05","#8A260E","#2E3679","#793F3F","#840F14","#401C56","#003C65","#741A09","#602A2A","#34134A","#114A1B","#27DDD1","#27DD8D","#4ADD27","#D3DD27","#DDA427","#DF2935","#DD27BC","#BA27DD","#3227DD","#2761DD","#27DDD1")

palette <- palette[1:paly]

#ggplot(plot_Basetotale, aes(word, tf_idf, fill = comcitant)) +
#  geom_col(show.legend = FALSE) +
#  labs(x = NULL, y = "tf-idf") +
#  facet_wrap(~comcitant, ncol = 2, scales = "free") +
#  coord_flip() +
#  scale_x_reordered() +
#  scale_fill_manual(values=c(palette))


plot_Basetotale2<-plot_Basetotale[,c(1,2)]


plot_Basetotale2$word<-str_replace(string = plot_Basetotale2$word, pattern = "___.*", replacement = "")


plot_Basetotale2$word<-toupper(plot_Basetotale2$word)

plot_Basetotale2$word<-trimws(plot_Basetotale2$word)


plot_Basetotale2$plural <- gsub('.{1}$','', plot_Basetotale2$word)


j<-unique(plot_Basetotale2$comcitant)

plot_Basetotale2$dede <- 0
for(i in 1: length(unique(plot_Basetotale2$comcitant))){
  k<-which(plot_Basetotale2$comcitant==j[i])
  for(m in k){if(any(plot_Basetotale2$plural[m]==plot_Basetotale2$word[k])){
    z<-which(plot_Basetotale2$plural[m]==plot_Basetotale2$word[k])
    if(k[z]<m){
      plot_Basetotale2$dede[k[z]]<-10
      plot_Basetotale2$dede[m]<-28}else{
        plot_Basetotale2$dede[k[z]]<-28
        plot_Basetotale2$dede[m]<-10}
  }else{
    plot_Basetotale2$dede[m]<-plot_Basetotale2$dede[m]}}
}



plot_Basetotale2<-plot_Basetotale2[plot_Basetotale2$dede!=28,]
plot_Basetotale2<-plot_Basetotale2[,c(1,2)]



j<-unique(plot_Basetotale2$comcitant)
plot_Basetotale2$comp<-0

for(i in 1: length(unique(plot_Basetotale2$comcitant))){
  k<-which(plot_Basetotale2$comcitant==j[i])[1:4]
  plot_Basetotale2$comp[k]<-1
}

plot_Basetotale2<-plot_Basetotale2[plot_Basetotale2$comp==T,]





for(i in 1: length(unique(plot_Basetotale2$comcitant))){
  k<-which(plot_Basetotale2$comcitant==j[i])[1]
  plot_Basetotale2$comp[k]<-paste(plot_Basetotale2$word[k],";",plot_Basetotale2$word[k+1],";",plot_Basetotale2$word[k+2],";",plot_Basetotale2$word[k+3])
}


plot_Basetotale2<-plot_Basetotale2[,c(1,3)]
plot_Basetotale2<-plot_Basetotale2[plot_Basetotale2$comp!=1,]



names(plot_Basetotale2)[names(plot_Basetotale2) == "comcitant"] <- "Com_ID"


#################################################################################################################################
#################################################################################################################################
# Fin de l'extraction des mots-clés --------------------------------------------------------------
#################################################################################################################################
#################################################################################################################################



top_nodes  <- top_nodes(graph, ordering_column = "degree", top_n = 10, top_n_per_com = 1)


community_labels <- community_labels(graph, community_name_column = "Community_name", community_size_column = "Size_com")

community_labels$identifiant<-str_sub (community_labels$Community_name, 1,2)

for(i in 1:nrow(community_labels)){
  j<-which(community_labels$identifiant[i] == plot_Basetotale2)
  community_labels$Community_name[i]<- plot_Basetotale2$comp[j]
}





library(ggraph)
library(ggrepel) 
library(ggnewscale)



ggraph(graph, "manual", x = x, y = y) + 
  geom_edge_arc(aes(color = color_edges, width = weight), alpha = 0.4, strength = 0.2, show.legend = FALSE) +
  scale_edge_width_continuous(range = c(0.1,2)) +
  scale_edge_colour_identity() +
  geom_node_point(aes(x=x, y=y, size = degree, fill = color), pch = 21, alpha = 0.9, show.legend = FALSE) +
  scale_size_continuous(range = c(0.2,13)) +
  scale_fill_identity() +
  new_scale("size") +
  geom_text_repel(data=top_nodes, aes(x=x, y=y, label = Label), size = 2, fontface="bold", alpha = 1, point.padding=NA, show.legend = FALSE) +
  geom_label_repel(data=community_labels, aes(x=x, y=y, label = Community_name, fill = color, size = Size_com), fontface="bold", alpha = 0.9, point.padding=NA, show.legend = FALSE) +
  scale_size_continuous(range = c(0.5,5)) +
  theme_void()

4- Co-citation 2010-2019

##### On a une colonne d'identifiant unique des articles et une colonne avec les refs biblios
##### recodées, on peut donc soumettre ça au package d'Aurelien

set.seed(16)


setwd("C:/Users/jgrad/Desktop/Network_Quality/Network_Quality")


load("Data_5_nodes.rda")
load("Data_7_finalbase.rda")




library(readr)
library(stringr)
#library(bibliometrix)
library(tidyverse)
library(biblionetwork)
#library(devtools)
#devtools::install_github("agoutsmedt/biblionetwork")


eoeoe2<-eoeoe

simple<-unique(eoeoe2$V2)
simple<-as.data.frame(simple)

#setdiff(desco$Cartel,simple[,1])

desco<-desco[desco$Cartel!=108237,]




comp<-cbind(simple,desco$Cartel)




desco$sloubi<-str_detect (string = desco$Datepubli, pattern = "2010|2011|2012|2013|2014|2015|2016|2017|2018|2019")
#desco$sloubi<-str_detect (string = desco$Datepubli, pattern = "1970|1971|1972|1973|1974|1975|1976|1977|1978|1979")
#desco$sloubi<-str_detect (string = desco$Datepubli, pattern = "1980|1981|1982|1983|1984|1985|1986|1987|1988|1989")
#desco$sloubi<-str_detect (string = desco$Datepubli, pattern = "1990|1991|1992|1993|1994|1995|1996|1997|1998|1999")
#desco$sloubi<-str_detect (string = desco$Datepubli, pattern = "2000|2001|2002|2003|2004|2005|2006|2007|2008|2009")



desco<-desco[desco$sloubi==T,]


Cartel<-desco$Cartel

eoeoe2$toofar<-"AB"
for(i in 1:nrow(eoeoe2)){
  if(eoeoe2$V2[i]%in%Cartel){eoeoe2$toofar[i]<-T}else{eoeoe2$toofar[i]<-F}}

eoeoe2<-eoeoe2[eoeoe2$toofar==T,]

Carlito<-unique(eoeoe2$V2)

Carlito<-as.data.frame(Carlito)
Cartel<-as.data.frame(Cartel)


Cabal<-cbind(Carlito,Cartel)


eoeoe2$V2<-as.character(eoeoe2$V2)
eoeoe2$identifiant<-as.character(eoeoe2$identifiant)
desco$Cartel<-as.character(desco$Cartel)


Basefinale<-biblio_coupling(eoeoe2, source = "identifiant", ref = "V2", normalized_weight_only = FALSE, weight_threshold = 2)



#devtools::install_github("agoutsmedt/networkflow")

library(biblionetwork)
library(magrittr)
library(dplyr)
library(tidygraph)
library(networkflow)
#devtools::install_github("agoutsmedt/networkflow")

library(tidygraph)
#devtools::install_github("ParkerICI/vite")
library(vite)


Edges_coupling2<-Basefinale[,-c(4)]


Nodes_coupling2<-unique(eoeoe2$identifiant)

Nodes_coupling2<-as.data.frame(Nodes_coupling2)

Nodes_coupling2$frequence<-0
for(i in 1:nrow(Nodes_coupling2)){
  j<-which(Nodes_coupling2$Nodes_coupling2[i] == eoeoe2$identifiant)[1]
  Nodes_coupling2$frequence[i]<-eoeoe2$frequence[j]
}


Nodes_coupling2$ids<-Nodes_coupling2$Nodes_coupling2


palette <- c("#1969B3","#01A5D8","#DA3E61","#3CB95F","#E0AF0C","#E25920","#6C7FC9","#DE9493","#CD242E","#6F4288","#B2EEF8","#7FF6FD","#FDB8D6","#8BF9A9","#FEF34A","#FEC57D","#DAEFFB","#FEE3E1","#FBB2A7","#EFD7F2","#5CAADA","#37D4F5","#F5779B","#62E186","#FBDA28","#FB8F4A","#A4B9EA","#FAC2C0","#EB6466","#AD87BC","#0B3074","#00517C","#871B2A","#1A6029","#7C4B05","#8A260E","#2E3679","#793F3F","#840F14","#401C56","#003C65","#741A09","#602A2A","#34134A","#114A1B","#27DDD1","#27DD8D","#4ADD27","#D3DD27","#DDA427","#DF2935","#DD27BC","#BA27DD","#3227DD","#2761DD","#27DDD1")

graph <- tbl_main_component(nodes = Nodes_coupling2, edges = Edges_coupling2, directed = FALSE, node_key = "Cartel", nb_components = 1)


## Varying the resolution of the algorithm results in a different partition and 
## different number of communities. A lower resolution means less communities, and conversely.
## The basic resolution of the leiden_workflow() is set by res_1 and equals 1 by default. 
## You can vary this parameter, but also try a second resolution with res_2 and a third one 
## with res_3
## On peut l'enlever avec un argument par défaut de 1


graph <- leiden_workflow(graph, res_1 = 0.5)

graph <- community_colors(graph, palette, community_column = "Com_ID")


graph <- graph %>%
  activate(nodes) %>%
  mutate(degree = centrality_degree())



graph <- community_names(graph, ordering_column = "degree", naming = "ids", community_column = "Com_ID")


graph <- graph %>%
  activate(nodes) %>% 
  mutate(size = frequence) # use here what you will use for the size of the nodes in the graph. Force Atlas will take care of avoiding overlapping


######## First.iter initiallement 5000, j'ai baissé pour arriver à le faire tourner


graph <- vite::complete_forceatlas2(graph, first.iter = 10000, overlap.method = "repel", overlap.iter = 1500)
## Total number of iterations: 10000
## Total number of iterations: 1500
top_nodes  <- top_nodes(graph, ordering_column = "degree", top_n = 10, top_n_per_com = 1)


community_labels2 <- community_labels(graph, community_name_column = "Community_name", community_size_column = "Size_com")


library(ggraph)
library(ggrepel) 
library(ggnewscale)


graph456<-as.data.frame(graph)




ggraph(graph, "manual", x = x, y = y) + 
  geom_edge_arc(aes(color = color_edges, width = weight), alpha = 0.4, strength = 0.2, show.legend = FALSE) +
  scale_edge_width_continuous(range = c(0.1,2)) +
  scale_edge_colour_identity() +
  geom_node_point(aes(x=x, y=y, size = degree, fill = color), pch = 21, alpha = 0.9, show.legend = FALSE) +
  scale_size_continuous(range = c(0.2,13)) +
  scale_fill_identity() +
  new_scale("size") +
  geom_text_repel(data=top_nodes, aes(x=x, y=y, label = Label), size = 2, fontface="bold", alpha = 1, point.padding=NA, show.legend = FALSE) +
  geom_label_repel(data=community_labels2, aes(x=x, y=y, label = Community_name, fill = color, size = Size_com), fontface="bold", alpha = 0.9, point.padding=NA, show.legend = FALSE) +
  scale_size_continuous(range = c(0.5,5)) +
  theme_void()

graph123<-graph123[,c(1,9)]
graph456<-graph456[,c(1,4)]



eoeoe$comcitant<-0
for(i in 1:nrow(graph123)){
  j<-which(eoeoe$V2 == graph123$Id[i])
  eoeoe$comcitant[j]<-graph123$Com_ID[i]
}


eoeoe$comcite<-0
for(i in 1:nrow(graph456)){
  j<-which(eoeoe$identifiant == graph456$Id[i])
  eoeoe$comcite[j]<-graph456$Com_ID[i]
}



eoeoe4<-eoeoe
eoeoe4<-eoeoe4[eoeoe4$comcitant!=0,]
eoeoe4<-eoeoe4[eoeoe4$comcite!=0,]


community_labels2$ID<-gsub("-.*", "",community_labels2$Community_name)

community_labels2$IDil<-gsub(".*-", "",community_labels2$Community_name)


community_labels2$IDcompl<-"AB"
for(i in 1:nrow(community_labels2)){
  j<-which(community_labels2$IDil[i] == eoeoe$identifiant)
  z<-which(paste(eoeoe$Firstauthor[j],eoeoe$Datepubli[j],eoeoe$Issue[j],eoeoe$Page[j])==eoeoe$identifiant[j])[1]
  community_labels2$IDcompl[i] <- eoeoe$V1[j[z]]
}


tableau<-as.data.frame.matrix(prop.table(table(eoeoe4$comcitant,eoeoe4$comcite),margin=1)*100)
library(dplyr)
tableau<-tableau %>% mutate_if(is.numeric, ~round(., 1))


community_labels<-community_labels[order(community_labels$identifiant),]
row.names(tableau) <- community_labels$Community_name

community_labels2<-community_labels2[order(community_labels2$Community_name),]
colnames(tableau)<- community_labels2$ID


for(i in 1:nrow(community_labels2)){
  community_labels2$IDcompl[i]<-paste(i,"-",community_labels2$IDcompl[i])
}

Legend<-community_labels2[,c(8)]

Legend<-as.data.frame(Legend)

names(Legend)[names(Legend) == "IDcompl"] <- "Complete reference of the clusters"

library(knitr)
library(kableExtra)


kable(Legend)
Complete reference of the clusters
1 - Melitz, M., The impact of trade on intra-industry reallocations and aggregate industry productivity (2003) Econometrica, 71 (6), pp. 1695-1725;
2 - Corbett, C.J., Montes-Sancho, M.J., Kirsch, D.A., The financial impact of ISO 9000 certification in the United States: an empirical analysis (2005) Manag Sci, 51, pp. 1046-1059;
3 - Akerlof, G.A., The market for” lemons”: Quality uncertainty and the market mechanism (1970) The quarterly journal of economics, 84 (3), pp. 488-500;
4 - Bartley, T., Institutional Emergence in an Era of Globalization: The Rise of Transnational Private Regulation of Labor and Environmental Conditions (2007) American Journal of Sociology, 113, pp. 297-351;
5 - Nelson, P., Information and consumer behavior (1970) The Journal of Political Economy, 78 (2), pp. 311-329;
6 - Kaynak, H., The relationship between total quality management practices and their effects on firm performance (2003) Journal of Operations Management, 21 (4), pp. 405-435;
7 - Jaffee, D., (2007) Brewing justice. Fair trade coffee, sustainability, and survival, , Univ of California Press;
8 - Cachon, G.P., Supply chain coordination with contracts (2003) Handbooks in Operations Research and Management Science: Supply Chain Management, , Graves S, de Kok T, eds, Chap. 6 (Elsevier, Amsterdam);
9 - Maertens, M., Swinnen, J.F.M., Trade, standards, and poverty: evidence from Senegal (2009) World Dev., 37 (1), pp. 161-178;
10 - Tay, A., Assessing Competition in Hospital Care Markets: The Importance of Accounting for Quality Differentiation (2003) RAND Journal of Economics, 34 (4), pp. 786-814;
11 - Zhu, Q., Sarkis, J., Relationships between operational practices and performance among early adopters of green supply chain management practices in Chinese manufacturing enterprises (2004) Journal of Operations Management, 22 (3), pp. 265-289;
12 - Feichtinger, G., Hartl, R.F., Sethi, S.P., Dynamic optimal control models in advertising: Recent developments (1994) Management Science, 40 (2), pp. 195-226;
13 - Lancaster, K., A new approach to consumer theory (1966) Journal of Political Economics, 74, pp. 132-157;
14 - Berry, S., Levinsohn, J., Pakes, A., Automobile Prices in Market Equilibrium (1995) Econometrica, 63, pp. 841-890;
15 - Manova, K., Zhang, Z., China’s exporters and importers: firms, products and trade partners (2009) NBER Working Paper 15249;
16 - Blackburn, J., Scudder, G., Supply chain strategies for perishable products: The case of fresh produce (2009) Production and Operations Management, 18 (2), pp. 129-137;
17 - Zeithaml, V.A., Consumer perceptions of price, quality, and value: A means-end model and synthesis of evidence (1988) J. Mark., 52, pp. 2-22
18 - Li, L., Information sharing in a supply chain with horizontal competition (2002) Management Sci., 48 (9), pp. 1196-1212;
19 - Swann, G.M.P., (2010) The economics of standardization: An update, , Report for the UK Department of Business, Innovation and Skills (BIS);
20 - Arora, A., Fosfuri, A., Licensing the Market for Technology (2003) Journal of Economic Behavior & Organization, 52, pp. 277-295;
21 - Naveh, E., Erez, M., Innovation and attention to detail in the quality improvement paradigm (2004) Manage. Sci., 50 (11), pp. 1576-1586;

5- Connect the communities 2010-2019

########################################################################################
##############################################################################################################
# Connecter les communautés -----------------------------
##############################################################################################################
##############################################################################################################


tableau %>%
  kbl() %>%
  kable_styling()
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21
SEARCH ; ADVERTISING ; FIRM ; SELLERS 2.8 1.0 47.5 0.8 27.0 0.7 0.6 2.1 0.9 1.9 0.1 2.8 2.5 6.8 0.1 0.0 0.6 1.7 0.0 0.0 0.0
TRADE ; PRODUCTIVITY ; FIRM ; EXPORT 90.9 0.8 0.4 0.0 0.4 0.1 0.1 0.0 1.4 0.1 0.0 0.0 0.0 0.4 5.3 0.0 0.1 0.0 0.1 0.0 0.0
ISO ; 14001 ; 9000 ; ENVIRONMENTAL 0.6 60.4 0.4 4.1 1.7 23.6 0.8 0.4 0.2 0.1 7.0 0.0 0.1 0.0 0.0 0.0 0.1 0.0 0.0 0.0 0.6
COFFEE ; FARMERS ; GOVERNANCE ; FAIR 5.3 2.6 0.1 17.4 1.3 0.2 46.0 0.0 27.0 0.0 0.0 0.0 0.0 0.0 0.1 0.0 0.0 0.0 0.1 0.0 0.1
SUPPLIER ; CHANNEL ; CONTRACT ; OUTSOURCING 1.3 2.0 3.5 0.3 3.6 2.7 0.0 64.4 0.0 1.5 0.5 16.9 0.0 0.0 0.0 0.7 0.0 2.0 0.3 0.0 0.3
PATENTS ; STANDARDISATION ; LICENSING ; STANDARDIZATION 1.5 4.0 2.9 76.0 3.7 2.1 0.1 0.4 0.0 0.1 0.1 0.1 0.0 0.0 0.0 0.4 0.0 0.1 4.4 3.9 0.0
LOT ; ITEMS ; DEFECTIVE ; JABER 0.0 0.0 0.0 0.0 0.0 92.3 0.0 0.0 0.0 0.0 7.7 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
SEAFOOD ; MSC ; SALMON ; FISH 2.3 0.5 1.4 0.0 8.2 0.0 0.5 0.0 0.0 0.0 0.0 0.0 82.7 0.5 4.1 0.0 0.0 0.0 0.0 0.0 0.0
HOSPITAL ; LOOP ; PATIENTS ; ALTRUISTIC 0.3 0.0 7.0 0.0 0.0 0.0 0.0 0.0 0.0 92.0 0.0 0.0 0.7 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
SERVICE ; TRANSIT ; SATISFACTION ; PASSENGER 0.0 0.0 1.0 0.0 0.0 9.4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 89.6 0.0 0.0 0.0 0.0
PERISHABLE ; SHELF ; ARC ; DETERIORATING 1.0 0.0 0.0 0.0 1.0 2.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 96.0 0.0 0.0 0.0 0.0 0.0

6- Bibliographic coupling 2000-2009

#####################################################################################################################
#####################################################################################################################
# Coupling Co-citation 2000-2009 -------------------
#####################################################################################################################
#####################################################################################################################




#####################################################################################################################
#####################################################################################################################
# Bibliographic Coupling 2000-2009----------------------------------------------------
#####################################################################################################################
#####################################################################################################################


##### On a une colonne d'identifiant unique des articles et une colonne avec les refs biblios
##### recodées, on peut donc soumettre ça au package d'Aurelien

set.seed(12)

setwd("C:/Users/jgrad/Desktop/Network_Quality/Network_Quality")

load("Data_5_nodes.rda")
load("Data_7_finalbase.rda")


library(readr)
library(stringr)
#library(bibliometrix)
library(tidyverse)
library(biblionetwork)
#library(devtools)
#devtools::install_github("agoutsmedt/biblionetwork")


eoeoe2<-eoeoe

simple<-unique(eoeoe2$V2)
simple<-as.data.frame(simple)

#setdiff(desco$Cartel,simple[,1])

desco<-desco[desco$Cartel!=108237,]


comp<-cbind(simple,desco$Cartel)




desco$sloubi<-str_detect (string = desco$Datepubli, pattern = "2000|2001|2002|2003|2004|2005|2006|2007|2008|2009")
#desco$sloubi<-str_detect (string = desco$Datepubli, pattern = "1970|1971|1972|1973|1974|1975|1976|1977|1978|1979|1980|1981|1982|1983|1984|1985|1986|1987|1988|1989|1990|1991|1992|1993|1994|1995|1996|1997|1998|1990|2000")

desco<-desco[desco$sloubi==T,]


Cartel<-desco$Cartel

eoeoe2$toofar<-"AB"
for(i in 1:nrow(eoeoe2)){
  if(eoeoe2$V2[i]%in%Cartel){eoeoe2$toofar[i]<-T}else{eoeoe2$toofar[i]<-F}}

eoeoe2<-eoeoe2[eoeoe2$toofar==T,]

Carlito<-unique(eoeoe2$V2)

Carlito<-as.data.frame(Carlito)
Cartel<-as.data.frame(Cartel)


Cabal<-cbind(Carlito,Cartel)


eoeoe2$V2<-as.character(eoeoe2$V2)
eoeoe2$identifiant<-as.character(eoeoe2$identifiant)
desco$Cartel<-as.character(desco$Cartel)



Basefinale<-biblio_coupling(eoeoe2, source = "V2", ref = "identifiant", normalized_weight_only = FALSE, weight_threshold = 2)



#devtools::install_github("agoutsmedt/networkflow")

library(biblionetwork)
library(magrittr)
library(dplyr)
library(tidygraph)
library(networkflow)
library(tidygraph)
#devtools::install_github("ParkerICI/vite")
library(vite)




Edges_coupling2<-Basefinale[,-c(4)]


Nodes_coupling2<-desco

Nodes_coupling2$frequence<-1

Nodes_coupling2$Datepubli<-as.character(Nodes_coupling2$Datepubli)

Nodes_coupling2$author_date<-paste(Nodes_coupling2$Cartel,Nodes_coupling2$Firstauthor,Nodes_coupling2$Datepubli)

palette <- c("#1969B3","#01A5D8","#DA3E61","#3CB95F","#E0AF0C","#E25920","#6C7FC9","#DE9493","#CD242E","#6F4288","#B2EEF8","#7FF6FD","#FDB8D6","#8BF9A9","#FEF34A","#FEC57D","#DAEFFB","#FEE3E1","#FBB2A7","#EFD7F2","#5CAADA","#37D4F5","#F5779B","#62E186","#FBDA28","#FB8F4A","#A4B9EA","#FAC2C0","#EB6466","#AD87BC","#0B3074","#00517C","#871B2A","#1A6029","#7C4B05","#8A260E","#2E3679","#793F3F","#840F14","#401C56","#003C65","#741A09","#602A2A","#34134A","#114A1B","#27DDD1","#27DD8D","#4ADD27","#D3DD27","#DDA427","#DF2935","#DD27BC","#BA27DD","#3227DD","#2761DD","#27DDD1")

graph <- tbl_main_component(nodes = Nodes_coupling2, edges = Edges_coupling2, directed = FALSE, node_key = "Cartel", nb_components = 1)

graph <- leiden_workflow(graph, res_1 = 1)

graph <- community_colors(graph, palette, community_column = "Com_ID")


graph <- graph %>%
  activate(nodes) %>%
  mutate(degree = centrality_degree())



graph <- community_names(graph, ordering_column = "degree", naming = "author_date", community_column = "Com_ID")


graph <- graph %>%
  activate(nodes) %>% 
  mutate(size = degree) # use here what you will use for the size of the nodes in the graph. Force Atlas will take care of avoiding overlapping

graph <- vite::complete_forceatlas2(graph, first.iter = 10000, overlap.method = "repel", overlap.iter = 1000)
## Total number of iterations: 7037
## Total number of iterations: 1000
graph123<-as.data.frame(graph)



#################################################################################################################
#################################################################################################################
# On extrait les abstracts pour faire de l'analyse textuelle ---------------------------------
#################################################################################################################
#################################################################################################################


load("Data_4_Abstracts.rda")


zalerit$comcitant<-0
for(i in 1:nrow(graph123)){
  j<-which(zalerit$Cartel == graph123$Id[i])
  zalerit$comcitant[j]<-graph123$Com_ID[i]
}


library(dplyr)
library(janeaustenr) #Inutile je pense
library(tidytext)
library(gutenbergr)  #Idem
library(pdftools)
library(tidyverse)
library(qdapRegex)


zaler2<-zalerit[,c(1,3)]

zaler2<-zaler2[zaler2$comcitant!=0,]

zaler2$V1<-as.character(zaler2$V1)
zaler2$comcitant<-as.character(zaler2$comcitant)



paly<-length(table(zaler2$comcitant))


Basetotale_words <- zaler2 %>%
  unnest_tokens(word, V1) %>%
  count(comcitant, word, sort = TRUE)



# On supprime les mots de deux lettres et de une lettre
Basetotale_words$word<-rm_nchar_words(Basetotale_words$word, 2)
Basetotale_words$word<-rm_nchar_words(Basetotale_words$word, 1)


# On remplace le vide que cree l'etape precedente par des NA et on supprime les NA
Basetotale_words$word[Basetotale_words$word==""] <- NA
Basetotale_words <- na.omit(Basetotale_words)


mystopwords <- tibble(word = c("qmi","consumerswho"))


Basetotale_words <- anti_join(Basetotale_words, mystopwords,
                              by = "word")


plot_Basetotale <- Basetotale_words %>%
  bind_tf_idf(word, comcitant, n) %>%
  mutate(word = str_remove_all(word, "_")) %>%
  group_by(comcitant) %>%
  slice_max(tf_idf, n = 25) %>%
  ungroup() %>%
  mutate(word = reorder_within(word, tf_idf, comcitant)) %>%
  mutate(comcitant = factor(comcitant))



palette <- c("#1969B3","#01A5D8","#DA3E61","#3CB95F","#E0AF0C","#E25920","#6C7FC9","#DE9493","#CD242E","#6F4288","#B2EEF8","#7FF6FD","#FDB8D6","#8BF9A9","#FEF34A","#FEC57D","#DAEFFB","#FEE3E1","#FBB2A7","#EFD7F2","#5CAADA","#37D4F5","#F5779B","#62E186","#FBDA28","#FB8F4A","#A4B9EA","#FAC2C0","#EB6466","#AD87BC","#0B3074","#00517C","#871B2A","#1A6029","#7C4B05","#8A260E","#2E3679","#793F3F","#840F14","#401C56","#003C65","#741A09","#602A2A","#34134A","#114A1B","#27DDD1","#27DD8D","#4ADD27","#D3DD27","#DDA427","#DF2935","#DD27BC","#BA27DD","#3227DD","#2761DD","#27DDD1")

palette <- palette[1:paly]

#ggplot(plot_Basetotale, aes(word, tf_idf, fill = comcitant)) +
#  geom_col(show.legend = FALSE) +
#  labs(x = NULL, y = "tf-idf") +
#  facet_wrap(~comcitant, ncol = 2, scales = "free") +
#  coord_flip() +
#  scale_x_reordered() +
#  scale_fill_manual(values=c(palette))


plot_Basetotale2<-plot_Basetotale[,c(1,2)]


plot_Basetotale2$word<-str_replace(string = plot_Basetotale2$word, pattern = "___.*", replacement = "")


plot_Basetotale2$word<-toupper(plot_Basetotale2$word)

plot_Basetotale2$word<-trimws(plot_Basetotale2$word)


plot_Basetotale2$plural <- gsub('.{1}$','', plot_Basetotale2$word)


j<-unique(plot_Basetotale2$comcitant)

plot_Basetotale2$dede <- 0
for(i in 1: length(unique(plot_Basetotale2$comcitant))){
  k<-which(plot_Basetotale2$comcitant==j[i])
  for(m in k){if(any(plot_Basetotale2$plural[m]==plot_Basetotale2$word[k])){
    z<-which(plot_Basetotale2$plural[m]==plot_Basetotale2$word[k])
    if(k[z]<m){
      plot_Basetotale2$dede[k[z]]<-10
      plot_Basetotale2$dede[m]<-28}else{
        plot_Basetotale2$dede[k[z]]<-28
        plot_Basetotale2$dede[m]<-10}
  }else{
    plot_Basetotale2$dede[m]<-plot_Basetotale2$dede[m]}}
}



plot_Basetotale2<-plot_Basetotale2[plot_Basetotale2$dede!=28,]
plot_Basetotale2<-plot_Basetotale2[,c(1,2)]



j<-unique(plot_Basetotale2$comcitant)
plot_Basetotale2$comp<-0

for(i in 1: length(unique(plot_Basetotale2$comcitant))){
  k<-which(plot_Basetotale2$comcitant==j[i])[1:4]
  plot_Basetotale2$comp[k]<-1
}

plot_Basetotale2<-plot_Basetotale2[plot_Basetotale2$comp==T,]





for(i in 1: length(unique(plot_Basetotale2$comcitant))){
  k<-which(plot_Basetotale2$comcitant==j[i])[1]
  plot_Basetotale2$comp[k]<-paste(plot_Basetotale2$word[k],";",plot_Basetotale2$word[k+1],";",plot_Basetotale2$word[k+2],";",plot_Basetotale2$word[k+3])
}


plot_Basetotale2<-plot_Basetotale2[,c(1,3)]
plot_Basetotale2<-plot_Basetotale2[plot_Basetotale2$comp!=1,]



names(plot_Basetotale2)[names(plot_Basetotale2) == "comcitant"] <- "Com_ID"


#################################################################################################################################
#################################################################################################################################
# Fin de l'extraction des mots-clés --------------------------------------------------------------
#################################################################################################################################
#################################################################################################################################



top_nodes  <- top_nodes(graph, ordering_column = "degree", top_n = 10, top_n_per_com = 1)


community_labels <- community_labels(graph, community_name_column = "Community_name", community_size_column = "Size_com")

community_labels$identifiant<-str_sub (community_labels$Community_name, 1,2)

for(i in 1:nrow(community_labels)){
  j<-which(community_labels$identifiant[i] == plot_Basetotale2)
  community_labels$Community_name[i]<- plot_Basetotale2$comp[j]
}



library(ggraph)
library(ggrepel) 
library(ggnewscale)



ggraph(graph, "manual", x = x, y = y) + 
  geom_edge_arc(aes(color = color_edges, width = weight), alpha = 0.4, strength = 0.2, show.legend = FALSE) +
  scale_edge_width_continuous(range = c(0.1,2)) +
  scale_edge_colour_identity() +
  geom_node_point(aes(x=x, y=y, size = degree, fill = color), pch = 21, alpha = 0.9, show.legend = FALSE) +
  scale_size_continuous(range = c(0.2,13)) +
  scale_fill_identity() +
  new_scale("size") +
  geom_text_repel(data=top_nodes, aes(x=x, y=y, label = Label), size = 2, fontface="bold", alpha = 1, point.padding=NA, show.legend = FALSE) +
  geom_label_repel(data=community_labels, aes(x=x, y=y, label = Community_name, fill = color, size = Size_com), fontface="bold", alpha = 0.9, point.padding=NA, show.legend = FALSE) +
  scale_size_continuous(range = c(0.5,5)) +
  theme_void()

7-Cocitation 2000-2009

##### On a une colonne d'identifiant unique des articles et une colonne avec les refs biblios
##### recodées, on peut donc soumettre ça au package d'Aurelien

set.seed(12)

setwd("C:/Users/jgrad/Desktop/Network_Quality/Network_Quality")

load("Data_5_nodes.rda")
load("Data_7_finalbase.rda")



library(readr)
library(stringr)
#library(bibliometrix)
library(tidyverse)
library(biblionetwork)
#library(devtools)
#devtools::install_github("agoutsmedt/biblionetwork")


eoeoe2<-eoeoe

simple<-unique(eoeoe2$V2)
simple<-as.data.frame(simple)

#setdiff(desco$Cartel,simple[,1])

desco<-desco[desco$Cartel!=108237,]




comp<-cbind(simple,desco$Cartel)




desco$sloubi<-str_detect (string = desco$Datepubli, pattern = "2000|2001|2002|2003|2004|2005|2006|2007|2008|2009")
#desco$sloubi<-str_detect (string = desco$Datepubli, pattern = "1970|1971|1972|1973|1974|1975|1976|1977|1978|1979")
#desco$sloubi<-str_detect (string = desco$Datepubli, pattern = "1980|1981|1982|1983|1984|1985|1986|1987|1988|1989")
#desco$sloubi<-str_detect (string = desco$Datepubli, pattern = "1990|1991|1992|1993|1994|1995|1996|1997|1998|1999")
#desco$sloubi<-str_detect (string = desco$Datepubli, pattern = "2000|2001|2002|2003|2004|2005|2006|2007|2008|2009")



desco<-desco[desco$sloubi==T,]


Cartel<-desco$Cartel

eoeoe2$toofar<-"AB"
for(i in 1:nrow(eoeoe2)){
  if(eoeoe2$V2[i]%in%Cartel){eoeoe2$toofar[i]<-T}else{eoeoe2$toofar[i]<-F}}

eoeoe2<-eoeoe2[eoeoe2$toofar==T,]

Carlito<-unique(eoeoe2$V2)

Carlito<-as.data.frame(Carlito)
Cartel<-as.data.frame(Cartel)


Cabal<-cbind(Carlito,Cartel)


eoeoe2$V2<-as.character(eoeoe2$V2)
eoeoe2$identifiant<-as.character(eoeoe2$identifiant)
desco$Cartel<-as.character(desco$Cartel)


Basefinale<-biblio_coupling(eoeoe2, source = "identifiant", ref = "V2", normalized_weight_only = FALSE, weight_threshold = 2)



#devtools::install_github("agoutsmedt/networkflow")

library(biblionetwork)
library(magrittr)
library(dplyr)
library(tidygraph)
library(networkflow)
#devtools::install_github("agoutsmedt/networkflow")

library(tidygraph)
#devtools::install_github("ParkerICI/vite")
library(vite)


Edges_coupling2<-Basefinale[,-c(4)]


Nodes_coupling2<-unique(eoeoe2$identifiant)

Nodes_coupling2<-as.data.frame(Nodes_coupling2)

Nodes_coupling2$frequence<-0
for(i in 1:nrow(Nodes_coupling2)){
  j<-which(Nodes_coupling2$Nodes_coupling2[i] == eoeoe2$identifiant)[1]
  Nodes_coupling2$frequence[i]<-eoeoe2$frequence[j]
}


Nodes_coupling2$ids<-Nodes_coupling2$Nodes_coupling2


palette <- c("#1969B3","#01A5D8","#DA3E61","#3CB95F","#E0AF0C","#E25920","#6C7FC9","#DE9493","#CD242E","#6F4288","#B2EEF8","#7FF6FD","#FDB8D6","#8BF9A9","#FEF34A","#FEC57D","#DAEFFB","#FEE3E1","#FBB2A7","#EFD7F2","#5CAADA","#37D4F5","#F5779B","#62E186","#FBDA28","#FB8F4A","#A4B9EA","#FAC2C0","#EB6466","#AD87BC","#0B3074","#00517C","#871B2A","#1A6029","#7C4B05","#8A260E","#2E3679","#793F3F","#840F14","#401C56","#003C65","#741A09","#602A2A","#34134A","#114A1B","#27DDD1","#27DD8D","#4ADD27","#D3DD27","#DDA427","#DF2935","#DD27BC","#BA27DD","#3227DD","#2761DD","#27DDD1")

graph <- tbl_main_component(nodes = Nodes_coupling2, edges = Edges_coupling2, directed = FALSE, node_key = "Cartel", nb_components = 1)


## Varying the resolution of the algorithm results in a different partition and 
## different number of communities. A lower resolution means less communities, and conversely.
## The basic resolution of the leiden_workflow() is set by res_1 and equals 1 by default. 
## You can vary this parameter, but also try a second resolution with res_2 and a third one 
## with res_3
## On peut l'enlever avec un argument par défaut de 1


graph <- leiden_workflow(graph, res_1 = 0.5)

graph <- community_colors(graph, palette, community_column = "Com_ID")


graph <- graph %>%
  activate(nodes) %>%
  mutate(degree = centrality_degree())



graph <- community_names(graph, ordering_column = "degree", naming = "ids", community_column = "Com_ID")


graph <- graph %>%
  activate(nodes) %>% 
  mutate(size = frequence) # use here what you will use for the size of the nodes in the graph. Force Atlas will take care of avoiding overlapping


######## First.iter initiallement 5000, j'ai baissé pour arriver à le faire tourner


graph <- vite::complete_forceatlas2(graph, first.iter = 10000, overlap.method = "repel", overlap.iter = 1500)
## Total number of iterations: 10000
## Total number of iterations: 1500
top_nodes  <- top_nodes(graph, ordering_column = "degree", top_n = 10, top_n_per_com = 1)


community_labels2 <- community_labels(graph, community_name_column = "Community_name", community_size_column = "Size_com")


library(ggraph)
library(ggrepel) 
library(ggnewscale)


graph456<-as.data.frame(graph)



ggraph(graph, "manual", x = x, y = y) + 
  geom_edge_arc(aes(color = color_edges, width = weight), alpha = 0.4, strength = 0.2, show.legend = FALSE) +
  scale_edge_width_continuous(range = c(0.1,2)) +
  scale_edge_colour_identity() +
  geom_node_point(aes(x=x, y=y, size = degree, fill = color), pch = 21, alpha = 0.9, show.legend = FALSE) +
  scale_size_continuous(range = c(0.2,13)) +
  scale_fill_identity() +
  new_scale("size") +
  geom_text_repel(data=top_nodes, aes(x=x, y=y, label = Label), size = 2, fontface="bold", alpha = 1, point.padding=NA, show.legend = FALSE) +
  geom_label_repel(data=community_labels2, aes(x=x, y=y, label = Community_name, fill = color, size = Size_com), fontface="bold", alpha = 0.9, point.padding=NA, show.legend = FALSE) +
  scale_size_continuous(range = c(0.5,5)) +
  theme_void()

graph123<-graph123[,c(1,9)]
graph456<-graph456[,c(1,4)]



eoeoe$comcitant<-0
for(i in 1:nrow(graph123)){
  j<-which(eoeoe$V2 == graph123$Id[i])
  eoeoe$comcitant[j]<-graph123$Com_ID[i]
}


eoeoe$comcite<-0
for(i in 1:nrow(graph456)){
  j<-which(eoeoe$identifiant == graph456$Id[i])
  eoeoe$comcite[j]<-graph456$Com_ID[i]
}



eoeoe4<-eoeoe
eoeoe4<-eoeoe4[eoeoe4$comcitant!=0,]
eoeoe4<-eoeoe4[eoeoe4$comcite!=0,]


community_labels2$ID<-gsub("-.*", "",community_labels2$Community_name)

community_labels2$IDil<-gsub(".*-", "",community_labels2$Community_name)


community_labels2$IDcompl<-"AB"
for(i in 1:nrow(community_labels2)){
  j<-which(community_labels2$IDil[i] == eoeoe$identifiant)
  z<-which(paste(eoeoe$Firstauthor[j],eoeoe$Datepubli[j],eoeoe$Issue[j],eoeoe$Page[j])==eoeoe$identifiant[j])[1]
  community_labels2$IDcompl[i] <- eoeoe$V1[j[z]]
}


tableau<-as.data.frame.matrix(prop.table(table(eoeoe4$comcitant,eoeoe4$comcite),margin=1)*100)
library(dplyr)
tableau<-tableau %>% mutate_if(is.numeric, ~round(., 1))


community_labels<-community_labels[order(community_labels$identifiant),]
row.names(tableau) <- community_labels$Community_name

community_labels2<-community_labels2[order(community_labels2$Community_name),]
colnames(tableau)<- community_labels2$ID


for(i in 1:nrow(community_labels2)){
  community_labels2$IDcompl[i]<-paste(i,"-",community_labels2$IDcompl[i])
}

Legend<-community_labels2[,c(8)]

Legend<-as.data.frame(Legend)

names(Legend)[names(Legend) == "IDcompl"] <- "Complete reference of the clusters"

library(knitr)
library(kableExtra)


kable(Legend)
Complete reference of the clusters
1 - Flynn, B.B., Schroeder, R.G., Sakakibara, S., A framework for quality management research and an associated measurement instrument (1994) J. Oper. Manag., 11 (4), pp. 339-366;
2 - Akerlof, G.A., The market for” lemons”: Quality uncertainty and the market mechanism (1970) The quarterly journal of economics, 84 (3), pp. 488-500;
3 - DiMaggio, P.J., Powell, W.W., The Iron Cage Revisited: Institutional Isomorphism and Collective Rationality in Organizational Fields (1983) American Sociological Review, 48 (2), pp. 147-160;
4 - Mussa, M., Rosen, S., Monopoly and product quality (1978) Journal of Economic theory, 18, pp. 301-317;
5 - Williamson, O.E., (1985) The Economic Institutions of Capitalism, , Free Press, New York;
6 - Parasuraman, A., Berry, L.L., Zeithaml, V.A., Zeithaml, V.A., Berry, L.L., SERVQUAL: Multiple-item scale for measuring consumer perceptions of service quality (1988) Journal of Retailing, 64 (1), pp. 12-40;
7 - Darby, M., Karni, E., Free competition and the optimal amount of fraud (1973) Journal of Law and Economics, 16, pp. 67-88;
8 - Gereffi, G., Garcia-Johnson, R., Sasser, E., The NGO-industrial complex (2001) Foreign Policy July/Aug, pp. 56-65;
9 - Spence, A.M., Monopoly, quality, and regulation (1975) Bell Journal of Economics, 6 (2), pp. 417-429;
10 - Eliashberg, J., Shugan, S.M., Film Critics: Influencers or Predictors? (1997) Journal of Marketing, 61 (2), pp. 68-78;
11 - Dellavigna, S., Malmendier, U., Contract Design and Self-Control: Theory and Evidence (2004) Quarterly Journal of Economics, 119, pp. 353-402;
12 - Abrahamson, E., Managerial fads and fashions: The diffusion and rejection of innovations (1991) Acad. Manag. Rev., 16 (3), pp. 586-612;
13 - Rosenbaum, P., Rubin, D., The central role of the propensity score in observational studies for causal effects (1983) Biometrika, 70, pp. 41-55;
14 - Beaulieu, N.D., Quality information and consumer health plan choices (2002) Journal of Health Economics, 21 (1), pp. 43-63., DOI 10.1016/S0167-6296(01)00126-6, PII S0167629601001266;
15 - Arrow, K., Economic Welfare and the Allocation of Resources for Inventions (1962) The Rate and Direction of Inventive Activity: Economic and Social Factors, , R. Nelson, ed., Princeton, NJ: Princeton University Press;
16 - Becker, G.S., A note on restaurant pricing and other examples of social influences on price (1991) Journal of Political Economy, 99 (5), pp. 1109-1116;
17 - Funk, J.L., Methe, D.T., Market- and committee-based mechanisms in the creation and diffusion of global industry standards: The case of mobile communication (2001) Research Policy, 30 (4), pp. 589-610., DOI 10.1016/S0048-7333(00)00095-0, PII S0048733300000950;
18 - Poksinska, B., Dahlgaard, J.J., Eklund, J.A., Implementing ISO 14000 in Sweden: motives, benefits and comparisons with ISO 9000 (2003) International Journal of Quality and Reliability Management, 20, pp. 585-606;
19 - Maddala, G.S., Wu, S., A comparative study of unit root tests with panel data and a new simple test (1999) Oxford Bulletin of Economics and Statistics, 61, pp. 631-652;
20 - Salameh, M., Jaber, M., Economic production quantity model for items with imperfect quality (2000) International Journal of Production Economics, 64 (13), pp. 59-64;
21 - Takeyama, L., The welfare implications of unauthorized reproduction of intellectual property in the presence of demand network externalities (1994) Journal of Industrial Economics, 42, pp. 155-166;
22 - Seddon, J., (2000) The Case against ISO 9000, , Dublin: Oak Tree Press;
23 - Garrard, G.A., (1998) Cellular Communications: World-Wide Market Development, , Artech House Norwood, MA, USA;
24 - Withers, B.E., Ebrahimpour, M., Hikmet, N., An exploration of the impact of TQM and JIT on ISO 9000 registered firms (1997) International Journal of Production Economics, 53 (2), pp. 209-216;
25 - Hofstede, G., (1980) Culture’s Consequences: International Differences in Work-related Values, 5., Sage Publications, Inc;
26 - Gans, N., Customer loyalty and supplier quality competition (2002) Management Science, 48 (2), pp. 207-221;
27 - Sykes, A.O., (1995) Product Standards for Internationally Integrated Goods Markets, , Washington, DC: The Brookings Institution;
28 - Deaton, A.S., Muellbauer, J., An Almost Ideal Demand System (1980) American Economic Review, 70, pp. 312-326;
29 - Anupindi, R., Akella, R., Diversification under supply uncertainty (1993) Management Science, 39 (8), pp. 944-963;
30 - Zaibet, L., Bredhal, M., Gains from ISO Certification in the UK Meat Sector (1997) Agribusiness, 13 (4), pp. 375-384
31 - Heide, J.B., John, G., The role of dependence balancing in safeguarding transaction-specific assets in conventional channels (1988) J. Marketing, 52 (1), pp. 20-35;
32 - Kothari, S.P., Warner, J.B., Measuring long-horizon security price performance (1997) Journal of Financial Economics, 43, pp. 301-339;
33 - Kyle, A.S., Continuous auctions and insider trading (1985) Econometrica, 53 (6), pp. 1315-1335;
34 - Hamilton, J.T., (2004) All the News That’s Fit to Sell:.How the Market Transforms Information Into News, , Princeton: Princeton University Press;
35 - Hedges, L., Olkin, I., (1985) Statistical Methods for Meta-Analysis, , San Diego, CA: Academic Press, Ltd;

8- Connect the communities 2000-2009

########################################################################################
##############################################################################################################
# Connecter les communautés -----------------------------
##############################################################################################################
##############################################################################################################


tableau %>%
  kbl() %>%
  kable_styling()
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
BEEF ; HYPOTHETICAL ; WINE ; REPUTATION 1.2 41.0 2.1 2.6 1.6 1.2 42.2 1.9 1.3 0.7 0.7 0.1 0.0 0.1 0.0 2.2 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.7 0.0 0.2 0.0 0.0 0.0 0.0 0.0
HOSPITAL ; QUALITY ; MEDICARE ; PLAN 0.5 8.1 1.2 36.3 3.9 0.1 16.5 0.2 19.0 1.4 2.9 0.0 0.1 7.0 0.0 0.0 0.0 0.0 0.1 0.0 1.8 0.0 0.0 0.0 0.0 0.0 0.0 0.1 0.0 0.0 0.0 0.0 0.0 0.4 0.0
TQM ; ISO ; 9000 ; SIGMA 87.2 0.5 3.3 0.4 0.2 2.0 0.1 0.6 0.0 0.2 0.0 4.8 0.1 0.0 0.0 0.0 0.1 0.1 0.0 0.0 0.0 0.0 0.0 0.1 0.2 0.0 0.0 0.0 0.0 0.0 0.1 0.1 0.0 0.0 0.0
14001 ; ISO ; EMS ; GSCM 14.6 1.2 65.4 2.8 2.1 0.4 1.0 3.7 0.2 1.2 0.5 2.3 0.2 0.0 0.3 0.0 0.1 2.4 0.1 0.0 0.0 0.8 0.0 0.0 0.1 0.0 0.1 0.0 0.0 0.3 0.0 0.0 0.0 0.0 0.1
STANDARDIZATION ; NETWORK ; STANDARDS ; GSM 2.3 5.6 1.0 62.4 3.1 0.8 0.6 0.5 0.6 5.5 3.3 0.4 0.0 0.0 0.4 3.2 5.6 0.0 0.0 0.0 0.2 0.0 1.5 1.1 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.5 0.2 0.0
DISCLOSURE ; ADVERTISING ; DISCLOSE ; SPOT 0.7 55.1 0.6 16.0 0.8 1.7 1.9 0.0 0.5 15.8 5.0 0.4 0.0 0.7 0.0 0.8 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
TRADE ; PLANTS ; PRODUCTIVITY ; EXPORTING 0.4 1.5 1.6 2.7 81.5 0.0 1.0 1.2 7.3 0.8 0.0 0.2 0.6 0.0 0.6 0.0 0.0 0.0 0.3 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.2 0.0 0.0 0.0
SERVQUAL ; SATISFACTION ; INTENTIONS ; SERVICE 12.9 9.3 0.6 1.2 0.2 72.0 1.2 0.1 0.0 0.3 0.1 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.1 0.0 0.0 0.0 0.0 0.0 0.7 0.0 0.0 0.0 0.0 0.0 0.1 0.0 0.0 0.0 0.1
MANUFACTURER ; SHARING ; CHANNEL ; SUPPLIER 4.0 55.1 0.9 3.1 6.3 0.8 0.4 0.0 4.1 0.4 12.6 0.4 0.0 0.0 0.2 0.3 0.0 0.0 0.0 6.7 0.0 0.0 0.0 0.0 0.0 2.2 0.0 0.0 1.8 0.0 0.5 0.4 0.0 0.0 0.0
COFFEE ; FARMERS ; FAIR ; STANDARDS 1.1 1.2 2.2 0.5 3.9 0.3 3.6 71.2 0.0 0.4 0.1 0.1 14.7 0.0 0.0 0.2 0.1 0.0 0.0 0.0 0.0 0.1 0.0 0.0 0.0 0.0 0.1 0.0 0.0 0.1 0.0 0.0 0.0 0.0 0.0
LICENSING ; ROYALTY ; DRASTIC ; OUTSIDER 1.7 2.6 0.4 4.3 2.6 0.0 0.4 1.3 0.4 1.3 0.0 0.0 0.0 0.0 84.3 0.0 0.0 0.0 0.0 0.0 0.4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
STATISTIC ; ROOT ; AUGMENTED ; RANK 1.5 0.0 4.4 2.9 1.5 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 89.7 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0

9- Bibliographic coupling 1990-1999

#####################################################################################################################
#####################################################################################################################
# Coupling Co-citation 2000-2009 -------------------
#####################################################################################################################
#####################################################################################################################




#####################################################################################################################
#####################################################################################################################
# Bibliographic Coupling 2000-2009----------------------------------------------------
#####################################################################################################################
#####################################################################################################################


##### On a une colonne d'identifiant unique des articles et une colonne avec les refs biblios
##### recodées, on peut donc soumettre ça au package d'Aurelien

set.seed(12)

setwd("C:/Users/jgrad/Desktop/Network_Quality/Network_Quality")

load("Data_5_nodes.rda")
load("Data_7_finalbase.rda")


library(readr)
library(stringr)
#library(bibliometrix)
library(tidyverse)
library(biblionetwork)
#library(devtools)
#devtools::install_github("agoutsmedt/biblionetwork")


eoeoe2<-eoeoe

simple<-unique(eoeoe2$V2)
simple<-as.data.frame(simple)

#setdiff(desco$Cartel,simple[,1])

desco<-desco[desco$Cartel!=108237,]


comp<-cbind(simple,desco$Cartel)




desco$sloubi<-str_detect (string = desco$Datepubli, pattern = "1990|1991|1992|1993|1994|1995|1996|1997|1998|1999")
#desco$sloubi<-str_detect (string = desco$Datepubli, pattern = "1970|1971|1972|1973|1974|1975|1976|1977|1978|1979|1980|1981|1982|1983|1984|1985|1986|1987|1988|1989|1990|1991|1992|1993|1994|1995|1996|1997|1998|1990|2000")

desco<-desco[desco$sloubi==T,]


Cartel<-desco$Cartel

eoeoe2$toofar<-"AB"
for(i in 1:nrow(eoeoe2)){
  if(eoeoe2$V2[i]%in%Cartel){eoeoe2$toofar[i]<-T}else{eoeoe2$toofar[i]<-F}}

eoeoe2<-eoeoe2[eoeoe2$toofar==T,]

Carlito<-unique(eoeoe2$V2)

Carlito<-as.data.frame(Carlito)
Cartel<-as.data.frame(Cartel)


Cabal<-cbind(Carlito,Cartel)


eoeoe2$V2<-as.character(eoeoe2$V2)
eoeoe2$identifiant<-as.character(eoeoe2$identifiant)
desco$Cartel<-as.character(desco$Cartel)



Basefinale<-biblio_coupling(eoeoe2, source = "V2", ref = "identifiant", normalized_weight_only = FALSE, weight_threshold = 2)



#devtools::install_github("agoutsmedt/networkflow")

library(biblionetwork)
library(magrittr)
library(dplyr)
library(tidygraph)
library(networkflow)
library(tidygraph)
#devtools::install_github("ParkerICI/vite")
library(vite)




Edges_coupling2<-Basefinale[,-c(4)]


Nodes_coupling2<-desco

Nodes_coupling2$frequence<-1

Nodes_coupling2$Datepubli<-as.character(Nodes_coupling2$Datepubli)

Nodes_coupling2$author_date<-paste(Nodes_coupling2$Cartel,Nodes_coupling2$Firstauthor,Nodes_coupling2$Datepubli)

palette <- c("#1969B3","#01A5D8","#DA3E61","#3CB95F","#E0AF0C","#E25920","#6C7FC9","#DE9493","#CD242E","#6F4288","#B2EEF8","#7FF6FD","#FDB8D6","#8BF9A9","#FEF34A","#FEC57D","#DAEFFB","#FEE3E1","#FBB2A7","#EFD7F2","#5CAADA","#37D4F5","#F5779B","#62E186","#FBDA28","#FB8F4A","#A4B9EA","#FAC2C0","#EB6466","#AD87BC","#0B3074","#00517C","#871B2A","#1A6029","#7C4B05","#8A260E","#2E3679","#793F3F","#840F14","#401C56","#003C65","#741A09","#602A2A","#34134A","#114A1B","#27DDD1","#27DD8D","#4ADD27","#D3DD27","#DDA427","#DF2935","#DD27BC","#BA27DD","#3227DD","#2761DD","#27DDD1")

graph <- tbl_main_component(nodes = Nodes_coupling2, edges = Edges_coupling2, directed = FALSE, node_key = "Cartel", nb_components = 1)

graph <- leiden_workflow(graph, res_1 = 1)

graph <- community_colors(graph, palette, community_column = "Com_ID")


graph <- graph %>%
  activate(nodes) %>%
  mutate(degree = centrality_degree())



graph <- community_names(graph, ordering_column = "degree", naming = "author_date", community_column = "Com_ID")


graph <- graph %>%
  activate(nodes) %>% 
  mutate(size = degree) # use here what you will use for the size of the nodes in the graph. Force Atlas will take care of avoiding overlapping

graph <- vite::complete_forceatlas2(graph, first.iter = 10000, overlap.method = "repel", overlap.iter = 1000)
## Total number of iterations: 3453
## Total number of iterations: 1000
graph123<-as.data.frame(graph)



#################################################################################################################
#################################################################################################################
# On extrait les abstracts pour faire de l'analyse textuelle ---------------------------------
#################################################################################################################
#################################################################################################################


load("Data_4_Abstracts.rda")


zalerit$comcitant<-0
for(i in 1:nrow(graph123)){
  j<-which(zalerit$Cartel == graph123$Id[i])
  zalerit$comcitant[j]<-graph123$Com_ID[i]
}


library(dplyr)
library(janeaustenr) #Inutile je pense
library(tidytext)
library(gutenbergr)  #Idem
library(pdftools)
library(tidyverse)
library(qdapRegex)


zaler2<-zalerit[,c(1,3)]

zaler2<-zaler2[zaler2$comcitant!=0,]

zaler2$V1<-as.character(zaler2$V1)
zaler2$comcitant<-as.character(zaler2$comcitant)



paly<-length(table(zaler2$comcitant))


Basetotale_words <- zaler2 %>%
  unnest_tokens(word, V1) %>%
  count(comcitant, word, sort = TRUE)



# On supprime les mots de deux lettres et de une lettre
Basetotale_words$word<-rm_nchar_words(Basetotale_words$word, 2)
Basetotale_words$word<-rm_nchar_words(Basetotale_words$word, 1)


# On remplace le vide que cree l'etape precedente par des NA et on supprime les NA
Basetotale_words$word[Basetotale_words$word==""] <- NA
Basetotale_words <- na.omit(Basetotale_words)


mystopwords <- tibble(word = c("qmi","consumerswho"))


Basetotale_words <- anti_join(Basetotale_words, mystopwords,
                              by = "word")


plot_Basetotale <- Basetotale_words %>%
  bind_tf_idf(word, comcitant, n) %>%
  mutate(word = str_remove_all(word, "_")) %>%
  group_by(comcitant) %>%
  slice_max(tf_idf, n = 25) %>%
  ungroup() %>%
  mutate(word = reorder_within(word, tf_idf, comcitant)) %>%
  mutate(comcitant = factor(comcitant))



palette <- c("#1969B3","#01A5D8","#DA3E61","#3CB95F","#E0AF0C","#E25920","#6C7FC9","#DE9493","#CD242E","#6F4288","#B2EEF8","#7FF6FD","#FDB8D6","#8BF9A9","#FEF34A","#FEC57D","#DAEFFB","#FEE3E1","#FBB2A7","#EFD7F2","#5CAADA","#37D4F5","#F5779B","#62E186","#FBDA28","#FB8F4A","#A4B9EA","#FAC2C0","#EB6466","#AD87BC","#0B3074","#00517C","#871B2A","#1A6029","#7C4B05","#8A260E","#2E3679","#793F3F","#840F14","#401C56","#003C65","#741A09","#602A2A","#34134A","#114A1B","#27DDD1","#27DD8D","#4ADD27","#D3DD27","#DDA427","#DF2935","#DD27BC","#BA27DD","#3227DD","#2761DD","#27DDD1")

palette <- palette[1:paly]

#ggplot(plot_Basetotale, aes(word, tf_idf, fill = comcitant)) +
#  geom_col(show.legend = FALSE) +
#  labs(x = NULL, y = "tf-idf") +
#  facet_wrap(~comcitant, ncol = 2, scales = "free") +
#  coord_flip() +
#  scale_x_reordered() +
#  scale_fill_manual(values=c(palette))


plot_Basetotale2<-plot_Basetotale[,c(1,2)]


plot_Basetotale2$word<-str_replace(string = plot_Basetotale2$word, pattern = "___.*", replacement = "")


plot_Basetotale2$word<-toupper(plot_Basetotale2$word)

plot_Basetotale2$word<-trimws(plot_Basetotale2$word)


plot_Basetotale2$plural <- gsub('.{1}$','', plot_Basetotale2$word)


j<-unique(plot_Basetotale2$comcitant)

plot_Basetotale2$dede <- 0
for(i in 1: length(unique(plot_Basetotale2$comcitant))){
  k<-which(plot_Basetotale2$comcitant==j[i])
  for(m in k){if(any(plot_Basetotale2$plural[m]==plot_Basetotale2$word[k])){
    z<-which(plot_Basetotale2$plural[m]==plot_Basetotale2$word[k])
    if(k[z]<m){
      plot_Basetotale2$dede[k[z]]<-10
      plot_Basetotale2$dede[m]<-28}else{
        plot_Basetotale2$dede[k[z]]<-28
        plot_Basetotale2$dede[m]<-10}
  }else{
    plot_Basetotale2$dede[m]<-plot_Basetotale2$dede[m]}}
}



plot_Basetotale2<-plot_Basetotale2[plot_Basetotale2$dede!=28,]
plot_Basetotale2<-plot_Basetotale2[,c(1,2)]



j<-unique(plot_Basetotale2$comcitant)
plot_Basetotale2$comp<-0

for(i in 1: length(unique(plot_Basetotale2$comcitant))){
  k<-which(plot_Basetotale2$comcitant==j[i])[1:4]
  plot_Basetotale2$comp[k]<-1
}

plot_Basetotale2<-plot_Basetotale2[plot_Basetotale2$comp==T,]





for(i in 1: length(unique(plot_Basetotale2$comcitant))){
  k<-which(plot_Basetotale2$comcitant==j[i])[1]
  plot_Basetotale2$comp[k]<-paste(plot_Basetotale2$word[k],";",plot_Basetotale2$word[k+1],";",plot_Basetotale2$word[k+2],";",plot_Basetotale2$word[k+3])
}


plot_Basetotale2<-plot_Basetotale2[,c(1,3)]
plot_Basetotale2<-plot_Basetotale2[plot_Basetotale2$comp!=1,]



names(plot_Basetotale2)[names(plot_Basetotale2) == "comcitant"] <- "Com_ID"


#################################################################################################################################
#################################################################################################################################
# Fin de l'extraction des mots-clés --------------------------------------------------------------
#################################################################################################################################
#################################################################################################################################



top_nodes  <- top_nodes(graph, ordering_column = "degree", top_n = 10, top_n_per_com = 1)


community_labels <- community_labels(graph, community_name_column = "Community_name", community_size_column = "Size_com")

community_labels$identifiant<-str_sub (community_labels$Community_name, 1,2)

for(i in 1:nrow(community_labels)){
  j<-which(community_labels$identifiant[i] == plot_Basetotale2)
  community_labels$Community_name[i]<- plot_Basetotale2$comp[j]
}



library(ggraph)
library(ggrepel) 
library(ggnewscale)



ggraph(graph, "manual", x = x, y = y) + 
  geom_edge_arc(aes(color = color_edges, width = weight), alpha = 0.4, strength = 0.2, show.legend = FALSE) +
  scale_edge_width_continuous(range = c(0.1,2)) +
  scale_edge_colour_identity() +
  geom_node_point(aes(x=x, y=y, size = degree, fill = color), pch = 21, alpha = 0.9, show.legend = FALSE) +
  scale_size_continuous(range = c(0.2,13)) +
  scale_fill_identity() +
  new_scale("size") +
  geom_text_repel(data=top_nodes, aes(x=x, y=y, label = Label), size = 2, fontface="bold", alpha = 1, point.padding=NA, show.legend = FALSE) +
  geom_label_repel(data=community_labels, aes(x=x, y=y, label = Community_name, fill = color, size = Size_com), fontface="bold", alpha = 0.9, point.padding=NA, show.legend = FALSE) +
  scale_size_continuous(range = c(0.5,5)) +
  theme_void()

10-Cocitation 1990-1999

##### On a une colonne d'identifiant unique des articles et une colonne avec les refs biblios
##### recodées, on peut donc soumettre ça au package d'Aurelien

set.seed(12)

setwd("C:/Users/jgrad/Desktop/Network_Quality/Network_Quality")

load("Data_5_nodes.rda")
load("Data_7_finalbase.rda")



library(readr)
library(stringr)
#library(bibliometrix)
library(tidyverse)
library(biblionetwork)
#library(devtools)
#devtools::install_github("agoutsmedt/biblionetwork")


eoeoe2<-eoeoe

simple<-unique(eoeoe2$V2)
simple<-as.data.frame(simple)

#setdiff(desco$Cartel,simple[,1])

desco<-desco[desco$Cartel!=108237,]




comp<-cbind(simple,desco$Cartel)




#desco$sloubi<-str_detect (string = desco$Datepubli, pattern = "2000|2001|2002|2003|2004|2005|2006|2007|2008|2009")
#desco$sloubi<-str_detect (string = desco$Datepubli, pattern = "1970|1971|1972|1973|1974|1975|1976|1977|1978|1979")
#desco$sloubi<-str_detect (string = desco$Datepubli, pattern = "1980|1981|1982|1983|1984|1985|1986|1987|1988|1989")
desco$sloubi<-str_detect (string = desco$Datepubli, pattern = "1990|1991|1992|1993|1994|1995|1996|1997|1998|1999")
#desco$sloubi<-str_detect (string = desco$Datepubli, pattern = "2000|2001|2002|2003|2004|2005|2006|2007|2008|2009")



desco<-desco[desco$sloubi==T,]


Cartel<-desco$Cartel

eoeoe2$toofar<-"AB"
for(i in 1:nrow(eoeoe2)){
  if(eoeoe2$V2[i]%in%Cartel){eoeoe2$toofar[i]<-T}else{eoeoe2$toofar[i]<-F}}

eoeoe2<-eoeoe2[eoeoe2$toofar==T,]

Carlito<-unique(eoeoe2$V2)

Carlito<-as.data.frame(Carlito)
Cartel<-as.data.frame(Cartel)


Cabal<-cbind(Carlito,Cartel)


eoeoe2$V2<-as.character(eoeoe2$V2)
eoeoe2$identifiant<-as.character(eoeoe2$identifiant)
desco$Cartel<-as.character(desco$Cartel)


Basefinale<-biblio_coupling(eoeoe2, source = "identifiant", ref = "V2", normalized_weight_only = FALSE, weight_threshold = 2)



#devtools::install_github("agoutsmedt/networkflow")

library(biblionetwork)
library(magrittr)
library(dplyr)
library(tidygraph)
library(networkflow)
#devtools::install_github("agoutsmedt/networkflow")

library(tidygraph)
#devtools::install_github("ParkerICI/vite")
library(vite)


Edges_coupling2<-Basefinale[,-c(4)]


Nodes_coupling2<-unique(eoeoe2$identifiant)

Nodes_coupling2<-as.data.frame(Nodes_coupling2)

Nodes_coupling2$frequence<-0
for(i in 1:nrow(Nodes_coupling2)){
  j<-which(Nodes_coupling2$Nodes_coupling2[i] == eoeoe2$identifiant)[1]
  Nodes_coupling2$frequence[i]<-eoeoe2$frequence[j]
}


Nodes_coupling2$ids<-Nodes_coupling2$Nodes_coupling2


palette <- c("#1969B3","#01A5D8","#DA3E61","#3CB95F","#E0AF0C","#E25920","#6C7FC9","#DE9493","#CD242E","#6F4288","#B2EEF8","#7FF6FD","#FDB8D6","#8BF9A9","#FEF34A","#FEC57D","#DAEFFB","#FEE3E1","#FBB2A7","#EFD7F2","#5CAADA","#37D4F5","#F5779B","#62E186","#FBDA28","#FB8F4A","#A4B9EA","#FAC2C0","#EB6466","#AD87BC","#0B3074","#00517C","#871B2A","#1A6029","#7C4B05","#8A260E","#2E3679","#793F3F","#840F14","#401C56","#003C65","#741A09","#602A2A","#34134A","#114A1B","#27DDD1","#27DD8D","#4ADD27","#D3DD27","#DDA427","#DF2935","#DD27BC","#BA27DD","#3227DD","#2761DD","#27DDD1")

graph <- tbl_main_component(nodes = Nodes_coupling2, edges = Edges_coupling2, directed = FALSE, node_key = "Cartel", nb_components = 1)


## Varying the resolution of the algorithm results in a different partition and 
## different number of communities. A lower resolution means less communities, and conversely.
## The basic resolution of the leiden_workflow() is set by res_1 and equals 1 by default. 
## You can vary this parameter, but also try a second resolution with res_2 and a third one 
## with res_3
## On peut l'enlever avec un argument par défaut de 1


graph <- leiden_workflow(graph, res_1 = 0.5)

graph <- community_colors(graph, palette, community_column = "Com_ID")


graph <- graph %>%
  activate(nodes) %>%
  mutate(degree = centrality_degree())



graph <- community_names(graph, ordering_column = "degree", naming = "ids", community_column = "Com_ID")


graph <- graph %>%
  activate(nodes) %>% 
  mutate(size = frequence) # use here what you will use for the size of the nodes in the graph. Force Atlas will take care of avoiding overlapping


######## First.iter initiallement 5000, j'ai baissé pour arriver à le faire tourner


graph <- vite::complete_forceatlas2(graph, first.iter = 10000, overlap.method = "repel", overlap.iter = 1500)
## Total number of iterations: 10000
## Total number of iterations: 1500
top_nodes  <- top_nodes(graph, ordering_column = "degree", top_n = 10, top_n_per_com = 1)


community_labels2 <- community_labels(graph, community_name_column = "Community_name", community_size_column = "Size_com")


library(ggraph)
library(ggrepel) 
library(ggnewscale)


graph456<-as.data.frame(graph)



ggraph(graph, "manual", x = x, y = y) + 
  geom_edge_arc(aes(color = color_edges, width = weight), alpha = 0.4, strength = 0.2, show.legend = FALSE) +
  scale_edge_width_continuous(range = c(0.1,2)) +
  scale_edge_colour_identity() +
  geom_node_point(aes(x=x, y=y, size = degree, fill = color), pch = 21, alpha = 0.9, show.legend = FALSE) +
  scale_size_continuous(range = c(0.2,13)) +
  scale_fill_identity() +
  new_scale("size") +
  geom_text_repel(data=top_nodes, aes(x=x, y=y, label = Label), size = 2, fontface="bold", alpha = 1, point.padding=NA, show.legend = FALSE) +
  geom_label_repel(data=community_labels2, aes(x=x, y=y, label = Community_name, fill = color, size = Size_com), fontface="bold", alpha = 0.9, point.padding=NA, show.legend = FALSE) +
  scale_size_continuous(range = c(0.5,5)) +
  theme_void()

graph123<-graph123[,c(1,9)]
graph456<-graph456[,c(1,4)]



eoeoe$comcitant<-0
for(i in 1:nrow(graph123)){
  j<-which(eoeoe$V2 == graph123$Id[i])
  eoeoe$comcitant[j]<-graph123$Com_ID[i]
}


eoeoe$comcite<-0
for(i in 1:nrow(graph456)){
  j<-which(eoeoe$identifiant == graph456$Id[i])
  eoeoe$comcite[j]<-graph456$Com_ID[i]
}



eoeoe4<-eoeoe
eoeoe4<-eoeoe4[eoeoe4$comcitant!=0,]
eoeoe4<-eoeoe4[eoeoe4$comcite!=0,]


community_labels2$ID<-gsub("-.*", "",community_labels2$Community_name)

community_labels2$IDil<-gsub(".*-", "",community_labels2$Community_name)


community_labels2$IDcompl<-"AB"
for(i in 1:nrow(community_labels2)){
  j<-which(community_labels2$IDil[i] == eoeoe$identifiant)
  z<-which(paste(eoeoe$Firstauthor[j],eoeoe$Datepubli[j],eoeoe$Issue[j],eoeoe$Page[j])==eoeoe$identifiant[j])[1]
  community_labels2$IDcompl[i] <- eoeoe$V1[j[z]]
}


tableau<-as.data.frame.matrix(prop.table(table(eoeoe4$comcitant,eoeoe4$comcite),margin=1)*100)
library(dplyr)
tableau<-tableau %>% mutate_if(is.numeric, ~round(., 1))


community_labels<-community_labels[order(community_labels$identifiant),]
row.names(tableau) <- community_labels$Community_name

community_labels2<-community_labels2[order(community_labels2$Community_name),]
colnames(tableau)<- community_labels2$ID


for(i in 1:nrow(community_labels2)){
  community_labels2$IDcompl[i]<-paste(i,"-",community_labels2$IDcompl[i])
}

Legend<-community_labels2[,c(8)]

Legend<-as.data.frame(Legend)

names(Legend)[names(Legend) == "IDcompl"] <- "Complete reference of the clusters"

library(knitr)
library(kableExtra)


kable(Legend)
Complete reference of the clusters
1 - Milgrom, P., Roberts, J., Price and advertising signals of product quality (1986) The Journal of Political Economy, 94 (4), pp. 796-821;
2 - Dierickx, I., Cool, K., Asset stock accumulation and the sustainability of competitive advantage (1989) Management Science, 35, pp. 1504-1511;
3 - Saraph, J.V., Benson, P.G., Schroeder, R.G., An instrument for measuring the critical factors of quality management (1989) Decis. Sci., 20 (4), pp. 810-829;
4 - Mussa, M., Rosen, S., Monopoly and product quality (1978) Journal of Economic theory, 18, pp. 301-317;
5 - Katz, M.L., Shapiro, C., Technology adoption in the presence of network externalities (1986) Journal of Political Economy, 94, pp. 822-841;
6 - Parasuraman, A., Zeithaml, V.A., Berry, L.L., A conceptual model of service quality and its implications for future research (1985) Journal of Marketing, 49, pp. 41-50;
7 - Hart, S.L., A natural-resource-based view of the firm (1995) Academy of Management Review, 20 (4), pp. 986-1014;
8 - Allen, R., Gertler, P., Regulation and the provision of quality to heterogeneous consumers: The case of prospective pricing of medical services (1991) Journal of Regulatory Economics, 3, pp. 361-375;
9 - Dunne, T., Roberts, M.R., Samuelson, L., Patterns of firm entry and exit in U.S. manufacturing industries (1988) RAND Journal of Economics, 19 (4), pp. 495-515;
10 - Hansen, L., Large sample properties of generalized method of moments estimators (1982) Econometrica, 50, pp. 1029-1054;
11 - Linder, S., (1961) An Essay on Trade and Transformation, , Uppsala, Almqvist & Wiksells;
12 - Rayner, P., Porter, L.J., BS5759/ISO 9000 - The experience of small and medium sized firms (1991) International Journal of Quality & Reliability Management, 8, pp. 16-28;
13 - Bentler, P.M., Bonett, D.G., Significant tests and goodness-of-fit in the analysis of covariance structures (1980) Psychological Bulleting, 88, pp. 588-606;
14 - Glaser, B.J., Strauss, A.L., (1967) The Discovery of Grounded Theory: Strategies for Qualitative Research, , Aldine Transaction, Piscataway, NJ;
15 - Frank, R., The demand for unobservable and other non-positional goods (1985) American Economic Review, 75 (1), pp. 101-116;
16 - Caswell, J.A., Johnson, G.V., Firm Strategic Response to Food Safety and Nutrition Regulation (1991) Economics of Food Safety, , J.A. Caswell (Ed) Elsevier Science Publishing Company New York;
17 - Barclay, M.J., Litzenberger, R.H., Announcement effects of new equity issues and use of intraday price data (1988) Journal of Financial Economics, 21, pp. 71-99;
18 - Nelson, R.R., (1993) National Innovation Systems: A Comparative Analysis, , Oxford University Press: New York;
19 - Joskow, P., Vertical Integration and Long-Term Contracts: The Case of Coal-Burning Electric Generation Plants (1985) Journal of Law, Economics, & Organization, 1, pp. 33-80;

11- Connect the communities 1990-1999

########################################################################################
##############################################################################################################
# Connecter les communautés -----------------------------
##############################################################################################################
##############################################################################################################


tableau %>%
  kbl() %>%
  kable_styling()
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19
ADVERTISING ; REPUTATION ; SELLERS ; INTERNET 86.8 2.2 1.0 3.9 1.3 1.7 0.1 0.5 0.2 0.1 0.5 0.0 0.0 0.0 1.3 0.2 0.0 0.0 0.1
TQM ; MANAGEMENT ; ALLIANCES ; ISO 2.2 38.6 43.1 0.8 0.7 1.9 8.2 0.1 0.0 0.2 0.1 0.4 1.4 0.9 0.2 0.0 0.3 0.4 0.4
MANUFACTURER ; CHANNEL ; RETAILER ; DIFFERENTIATION 12.5 1.0 0.2 78.2 3.1 0.0 0.2 1.2 1.9 0.3 1.4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
NETWORK ; SOFTWARE ; STANDARDS ; HARDWARE 4.8 17.4 0.8 18.2 57.7 0.0 0.6 0.1 0.0 0.1 0.1 0.0 0.0 0.2 0.1 0.0 0.0 0.1 0.0
PATIENTS ; HOSPITAL ; PROVIDER ; CARDIAC 12.7 2.6 0.9 10.5 1.3 0.4 0.4 43.0 0.9 27.2 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
SATISFACTION ; SERVICE ; SERVQUAL ; CUSTOMER 0.4 0.6 5.9 0.2 0.0 91.1 0.2 0.2 0.0 0.0 0.0 0.2 0.0 1.2 0.0 0.0 0.0 0.0 0.0
EXPORTING ; EXPORTERS ; COUPONING ; PARAMETERS 28.7 5.8 1.2 9.9 0.6 2.3 0.6 1.8 39.8 8.8 0.6 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
TRADE ; LICENSING ; SPECTRUM ; NORTHERN 15.5 5.2 1.0 9.3 7.2 0.0 0.0 0.0 0.0 1.0 59.8 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0
9000 ; ISO ; BUSINESSES ; SMES 0.0 0.0 7.2 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 92.8 0.0 0.0 0.0 0.0 0.0 0.0 0.0
FUNDS ; EARNINGS ; MUTUAL ; BOND 28.6 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 71.4 0.0 0.0
SAFETY ; FOOD ; REGULATION ; PROTECTION 19.0 4.8 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 4.8 0.0 71.4 0.0 0.0 0.0
BOX ; FILMS ; OFFICE ; MOTION 66.7 0.0 0.0 33.3 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
EXPERIMENTATION ; PAYOFF ; OLIGOPOLISTIC ; DISPERSION 92.6 0.0 0.0 3.7 0.0 0.0 0.0 0.0 0.0 0.0 3.7 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0